ZF错误路线重写
我的 layout.phtml 中有 2 个链接,引导程序中有一条路线:
1. Link:
echo $this->url(array('controller' => 'aktuelles', 'action' => 'index'), null, true );
// creates: http://localhost/aktuelles
2: Link
echo $this->url(array('controller' => 'projekte', 'action' => 'wohnen', 'projektId' => 26), 'projekte-galeria', false);
// creates: http://localhost/projekte/wohnen/26
Route:
$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();
$route = new Zend_Controller_Router_Route( 'projekte/wohnen/:projektId',
array(
'module' => 'web',
'controller' => 'projekte',
'action' => 'wohnen',
'projektId' => null)
);
$router->addRoute( 'projekte-galeria', $route);
当我加载页面时,所有内容都显示正确,并且 url 都正确。
问题:一旦我单击第二个链接(http://localhost/projekte/wohnen/26),第一个链接就会发生变化:
从: localhost/aktuelles
到: localhost/projekte/wohnen
为什么链接改变了?
I've got 2 links in my layout.phtml and a route in the bootstrap:
1. Link:
echo $this->url(array('controller' => 'aktuelles', 'action' => 'index'), null, true );
// creates: http://localhost/aktuelles
2: Link
echo $this->url(array('controller' => 'projekte', 'action' => 'wohnen', 'projektId' => 26), 'projekte-galeria', false);
// creates: http://localhost/projekte/wohnen/26
Route:
$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();
$route = new Zend_Controller_Router_Route( 'projekte/wohnen/:projektId',
array(
'module' => 'web',
'controller' => 'projekte',
'action' => 'wohnen',
'projektId' => null)
);
$router->addRoute( 'projekte-galeria', $route);
When I load the page everything is displayed correctly and the urls are all correct.
Problem: As soon as i click on the second link (http://localhost/projekte/wohnen/26), the first link is changing:
from: localhost/aktuelles
to : localhost/projekte/wohnen
Why is the link changed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试强制使用默认路由:使用
'default'
作为第一个 url 中的第二个参数,而不是null
。顺便说一句 -
'controller' => 部分'项目', '行动' =>第二个 url 中的 'wohnen'
是多余的,因为您在路由中预定义了这些参数。第二个链接可以这样简化:Try to force to use the default route: instead of
null
use'default'
as the second parameter in the first url.BTW - the part
'controller' => 'projekte', 'action' => 'wohnen'
in the second url is redundant, because you predefine these parameters in the route. The second link could by simplified like this:看看这个解决方案作为处理路由的替代方法Zend Framework 中的简单重写
Have a look at this solution as an alternative way to handle routes Simple rewrites in Zend Framework