开发者

How can I setup a simple custom route using Zend Framework?

开发者 https://www.devze.com 2022-12-27 04:14 出处:网络
I\'m looking to setup a custom route which supplies implicit paramete开发者_开发问答r names to a Zend_Application. Essentially, I have an incoming URL which looks like this:

I'm looking to setup a custom route which supplies implicit paramete开发者_开发问答r names to a Zend_Application. Essentially, I have an incoming URL which looks like this:

/StandardSystems/Dell/LatitudeE6500

I'd like that to be mapped to the StandardsystemsController, and I'd like that controller to be passed parameters "make" => "Dell" and "model" => "LatitudeE6500".

How can I setup such a system using Zend_Application and Zend_Controller_Router?

EDIT: I didn't explain myself all that clearly I guess -- if make and model aren't present I'd like to redirect the user to another action on the StandardsystemsController. currently, using Ballsacian1's answer with this in application.ini:

resources.router.routes.StandardSystem.route = "/StandardSystem/:make/:model"
resources.router.routes.StandardSystem.defaults.controller = "StandardSystem"
resources.router.routes.StandardSystem.defaults.action = "system"
resources.router.routes.StandardSystem.defaults.make = ""
resources.router.routes.StandardSystem.defaults.model = ""
resources.router.routes.StandardSystemDefault.route = "/StandardSystem"
resources.router.routes.StandardSystemDefault.defaults.controller = "StandardSystem"
resources.router.routes.StandardSystemDefault.defaults.action = "index"


You would first instantiate a new Zend_Controller_Router_Route to create your route.

$stdsys_route = new Zend_Controller_Router_Route(
    '/StandardSystems/:make/:model',
    array(
        'controller' => 'StandardsystemsController',
        'action' => 'myaction'
    );
);

This route then needs to be added to your router.

$front_controller = Zend_Controller_Front::getInstance();
$front_controller->getRouter()->addRoute('stdsys', $stdsys_route);

Now when you dispatch, the route should take effect.

References:

  • http://framework.zend.com/manual/en/zend.controller.router.html


Resources:

resources.router.routes.StandardSystems.route = "/StandardSystems/:make/:model"
resources.router.routes.StandardSystems.defaults.controller = "standardsystems"
resources.router.routes.StandardSystems.defaults.action = "index"
0

精彩评论

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

关注公众号