views:

65

answers:

2

Zend Framework:

I have the following url  /base/url/[number]/[string] 
OR                        /base/url/action/controller/param/value

I want in the case of /base/url/[number]/[string] to transform it to /base/url/controller/a/action/b/id/[number]/name/[string] The a and b are constants (i.e. each time I see a number in the place of the action, I use the same values).
Where can I catch the action and controller values before they are being dispatched?

+2  A: 

You can recieve action and controller in Controller Plugin in routeShutdown() (once after route is selected) or in preDispatch() (before every controller dispatch). I guess you would use routeShutdown. You have Request accessible, so you can set controller and action to anything at all..

How to write plugins

Tomáš Fejfar
A: 

You can create a custom Route to handle that kind of routes, and have them dispatched to the correct controller and URL.

For example:

$router = $front->getRouter();
$router->addRoute(
    'my_route',
    new Zend_Controller_Router_Route(
         ':number/:string',
         array(
              'controller' => 'your_controller',
              'action' => 'your_action'
         )
    )
);
Chris
So, How do I extract the number from the url? I need it to be /16/something -> /question/show/id/16
Itay Moav
Just use in your controller $this->_getParam('number') and $this->_getParam('string') whatever you put in :number you use that to extract, for example if your route is::page/:nameYou extract using $this->_getParam('page') and $this->_getParam('name').
Chris