开发者

Zend Routing can this be done

This is possible in Symfony with some routing magic but in Zend I'm not sure how to do this.

I want to make this url

开发者_开发知识库http://example.com/unit/view/id/[15]

look like this instead

http://example.com/unit/[15]/view/[name]

where unit/view is the controller/action and id/15 is parameter key=>value, and [name] is the name of the unit being retrieved (in this case unit id 15).


Yes, it can be done. Using the router:

In your bootstrap:

$router = $zendControllerFront->getRouter();
$router->addRoute('routeName', 
    new Zend_Controller_Router_Route('/unit/:id/view/:name'), 
    array('controller' => 'unit', 'action' => 'view')
);


You can add the route also in your application.ini:

resources.router.routes.myroute.route = ":controller/:id/:action/:name"

Then unit maps automatically to your controller (:controller variable here) and the action (:action). More information about these paramters used in Zend_Config files at the manual: http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.add-config

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜