具有无限参数的Zend_Controller_Router_Route的语法?

时间:2010-10-11 15:35:56

标签: php zend-framework router

我需要一个带有controller =>的Zend_Controller_Route_Route。 'downloads',action => 'index'和一个无限的参数变量。

www.domain.com/downloads/this/is/the/path/to/the/folder 

应该重定向到

DownloadsController > indexAction

我在考虑以下内容:

'downloads' => array(
        'route' => 'downloads/*',
        'defaults' => array('controller' => 'downloads', 'action' => 'index')

但是如何请求*作为参数?

1 个答案:

答案 0 :(得分:2)

您可以使用RegEx Route http://framework.zend.com/manual/de/zend.controller.router.html#zend.controller.router.routes.regex

$router = Zend_Controller_Front::getInstance()->getRouter(); // returns a rewrite router by default

$route['default'] = new Zend_Controller_Router_Route_Regex(
    '/downloads/(.*)',
    array(
        'controller'=> 'Downloads',
        'action'    => 'index',
    ),
    array(
        1           => 'downloadpath',
    )
);

$router->addRoute('default', $route['default']);

我没有测试过,但是那样的东西应该可以运行