0

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).

Lingo
  • 1,865
  • 2
  • 16
  • 14
  • Do you want the name to be looked up automatically (in a database or something like this) or do you add it to your route manually? – Fge Oct 23 '10 at 16:27

2 Answers2

2

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')
);
Andrew
  • 227,796
  • 193
  • 515
  • 708
0

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

Jurian Sluiman
  • 13,498
  • 3
  • 67
  • 99