Zend Route Regex和可选参数

时间:2021-10-14 18:03:56

I want to use a URL like this:

我想使用这样的URL:

site.com/car-list/param1/value1/param2/value2

"car" is variable and can be anytihng. i solved the "site.com/car-list" part like this:

“汽车”是可变的,可以是任何人。我解决了“site.com/car-list”这样的部分:

    $categoryRoute = new Zend_Controller_Router_Route_Regex(
        '(\b.+\-list\b)',
        array(
            'module' => 'default',
            'controller' => 'search',
            'action' => 'index'
        ),
        array(
            1 => 'productType'
        )
    );

I can get "car-list" when i want "productType" param. But i cant get rest of the url with $this->_getParam() in controller.

当我想要“productType”参数时,我可以获得“car-list”。但我无法在控制器中使用$ this - > _ getParam()来获取其余的url。

how can i do this? thanks.

我怎样才能做到这一点?谢谢。

1 个解决方案

#1


5  

Well, i don't see how to make it with Router_Route_Regex, but with Router_Route it would be easier (thought, i replace "-" with "/")

好吧,我没有看到如何使用Router_Route_Regex,但使用Router_Route它会更容易(想想,我用“/”替换“ - ”)

$categoryRoute = new Zend_Controller_Router_Route
    ':car/list/*',
    array(
        'module' => 'default',
        'controller' => 'search',
        'action' => 'index'
    )
);

magic happens due to the "/*" at the end of the string. :car variable can be got with $request->getParam('car');

由于字符串末尾的“/ *”而发生魔术。 :car变量可以用$ request-> getParam('car')获得;

#1


5  

Well, i don't see how to make it with Router_Route_Regex, but with Router_Route it would be easier (thought, i replace "-" with "/")

好吧,我没有看到如何使用Router_Route_Regex,但使用Router_Route它会更容易(想想,我用“/”替换“ - ”)

$categoryRoute = new Zend_Controller_Router_Route
    ':car/list/*',
    array(
        'module' => 'default',
        'controller' => 'search',
        'action' => 'index'
    )
);

magic happens due to the "/*" at the end of the string. :car variable can be got with $request->getParam('car');

由于字符串末尾的“/ *”而发生魔术。 :car变量可以用$ request-> getParam('car')获得;