views:

135

answers:

2

I'm looking to setup a custom route which supplies implicit parameter 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"
+2  A: 

Resources:

resources.router.routes.StandardSystems.route = "/StandardSystems/:make/:model"
resources.router.routes.StandardSystems.defaults.controller = "standardsystems"
resources.router.routes.StandardSystems.defaults.action = "index"
Ballsacian1
Nice! Is there a way to make it work if the index controller is sort of an "unknown computer" page, and it goes only to a "computer" action if make and model aren't specified? Currently it throws massive exceptions if make and model aren't specified....
Billy ONeal
Nevermind -- was able to figure it out. Posted that as an edit to my question. Thank you very much :)
Billy ONeal
+3  A: 

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:

erisco
Where does that code go? Index.php? Somewhere in Bootstrap.php?
Billy ONeal