我需要 zend 框架中 URL 重写的帮助。如果我打印以下 URL:
echo $this->url(array('controller'=>'guestbook','action'=>'edit','id'=>$entry->id), null, TRUE);
它会生成如下 url:http://localhost/guestbook/public/index.php/guestbook/edit/id/1 http://localhost/guestbook/public/index.php/guestbook/edit/id/1
但是我怎样才能生成像这样的网址:http://localhost/guestbook/public/index.php/guestbook/edit/1 http://localhost/guestbook/public/index.php/guestbook/edit/1在 zend 框架中?
我不想要'id'在网址中。请帮忙。
Zend 控制器路由器 http://framework.zend.com/manual/en/zend.controller.router.html将帮助您实现这一目标。
最简单的开始方法是在引导程序中添加以下内容(尚未真正测试,但它应该以最少的调试工作,请参阅提供的链接,因为它解释了很多内容,使用此代码只是为了开始了解路由如何工作):
$router = Zend_Controller_Front::getInstance()->getRouter();
$router->addRoute(
'guestbook_edit',
new Zend_Controller_Router_Route('guestbook/edit/:id',
array('controller' => 'guestbook',
'action' => 'edit'))
);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)