开发者

Zend Framework Router Getting /module/VALUE/controller/action

开发者 https://www.devze.com 2022-12-27 10:51 出处:网络
I\'ve been googling around and I can\'t seem to find anything which explains the use of ZF router well. I\'ve read the documentation on the site, which seems to only talk about re-routing.

I've been googling around and I can't seem to find anything which explains the use of ZF router well. I've read the documentation on the site, which seems to only talk about re-routing.

I am trying to make the format: /module/value/controller/action give /module/controller/action passing on value as a parameter

e.g. /store/johnsmithbigsale/home/newstuff would route to /store/home/newstuff pas开发者_开发百科sing on johnsmithbigsale as the value to a parameter with a hidden namespace e.g. storeName.

Some help would be greatful!


You can use Zend_Controller_Router_Route to map your url parts to modules, controllers, actions, and parameters that can be used in the controller by $this->_getParam('varName'). You can define these routes in the application.ini file or in the application bootstrap.

// custom city route
$route = new Zend_Controller_Router_Route(
    'cities/:city',
    array(
        'controller' => 'city',
        'action'     => 'view'
    )
);
$this->addRoute('city', $route);

// custom buy widgets route
$route = new Zend_Controller_Router_Route_Regex(
    'buy_(.+)_widgets/([0-9]+)(.*)',
    array(
        'controller' => 'widgets',
        'action'     => 'view'
    ),
    array(
        1 => 'nothing',
        2 => 'widget_id',
        3 => 'vars'
    )
);
$this->addRoute('widgets', $route);

The regex route is kind of specific to my app, but you can see that each match can get mapped to a parameter.

0

精彩评论

暂无评论...
验证码 换一张
取 消