我对自定义Zend路由器有问题。这是我的猫路由器
$frontController = Zend_Controller_Front::getInstance();
$router = $frontController->getRouter();
$router->addRoute('categories', new Zend_Controller_Router_Route(
'video/k/:id/:title',array(
'controller' => 'video',
'module' => 'default' ,
'action' => 'k',
'id' => '',
'title' =>''
)
));
$params = Zend_Controller_Front::getInstance()->getRequest()->getParams();
当我尝试 htttp://dev.dummy.com/video/k/1/foo 工作正常,但是
$this->url(array_merge($params, array('order' => 'title'))) or
$this->url(array_merge($params, array('order' => 'title')),'categories')
$this->url(array_merge($params, array('order' => 'title')),'categories', true)
d dect return htttp://dev.dummy.com/video/k/1/foo/order/title 仍返回 htttp://dev.dummy.com/video/k/1/foo 。
希望这有所帮助。谢谢。
尝试设置URL helper的第三个参数$reset
至true
:
$this->url(array_merge($params, array('order' => 'title')), 'categories', true)
这将重置默认参数。
(http://framework.zend.com/manual/1.12/en/zend.view.helpers.html#zend.view.helpers.initial.initial)
执行array_merge时,整数键将从启动开始。只需附加您的数组而不是array_merge:
$router->addRoute('categories', new Zend_Controller_Router_Route(
'index/test/:id/:title',array(
'controller' => 'index',
'module' => 'default' ,
'action' => 'test',
'id' => '',
'title' => ''
)
));
echo $this->url(array('order' => 'title'));
使用http://dev.dummy.com/video/k/1/foo和http://dev.dummy.chom.chom/video/k/k/1/foo/foo/order/title/。在这两种情况下,URL助手输出均为-htttp://dev.dummy.com/video/k/1/foo/order/title/title