2

我对自定义 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();

当我尝试http://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)

不返回htttp://dev.dummy.com/video/k/1/foo/order/title 仍然返回htttp://dev.dummy.com/video/k/1/foo

希望这有帮助。谢谢。

4

2 回答 2

0

When doing the array_merge, the integer keys will be reset to start from beginning. Just append your array instead of the 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')); 

Tried it with http://dev.dummy.com/video/k/1/foo and http://dev.dummy.chom/video/k/1/foo/order/title/. In both cases, the url helper output was - htttp://dev.dummy.com/video/k/1/foo/order/title

于 2012-11-04T19:19:37.263 回答
0

尝试将$reseturl-helper 的第三个参数设置为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

于 2012-11-04T10:45:36.397 回答