Hi,
So basically I am removing Default Routes within a Modular Application and would like to replicate the default routing behavior with addRoute(). Then I will extend on each Route (URI) with language prefixes etc.
However I am finding that I can't even mimic the default routing behavior? Is this a bug? The issue lies when I start trying to include the parameters functionality to accommodate both controller / action and module / controler / action.
The error I'm getting in the example below would be the same if I kept the default routes and begun writing my own for the language prefix. I have tried to keep it as standard and simple as possible.
Eg (In it's simplest form):
"Zend_Controller_Router_Rewrite comes preconfigured with a default route, which will match URIs in the shape of controller/action. Additionally, a module name may be specified as the first path element, allowing URIs of the form module/controller/action. Finally, it will also match any additional parameters appended to the URI by default - controller/action/var1/value1/var2/value2."
So: Bootstrap.php
http://hostname/index/index (controller / action) -> WorksCode:$frontController = Zend_Controller_Front::getInstance(); $router = $frontController->getRouter(); $router->removeDefaultRoutes(); $router->addRoute( 'controller_action_params', new Zend_Controller_Router_Route(':controller/:action/*', array('module' => 'default')) ); $router->addRoute( 'module_controller_action', new Zend_Controller_Router_Route(':module/:controller/:action') ); $router->addRoute( 'controller_action', new Zend_Controller_Router_Route(':controller/:action', array('module' => 'default')) );
http://hostname/user/index/index (module / controller / action) -> Works
http://hostname/index/index/key/param (controller / action / key /value) -> Works
http://hostname/user/index/index/key/param (module / controller / action / key /value) -> FAILS!
So I change the Code too:
http://hostname/index/index (controller / action) -> WorksCode:$frontController = Zend_Controller_Front::getInstance(); $router = $frontController->getRouter(); $router->removeDefaultRoutes(); $router->addRoute( 'module_controller_action_params', new Zend_Controller_Router_Route(':module/:controller/:action/*') ); $router->addRoute( 'controller_action_params', new Zend_Controller_Router_Route(':controller/:action/*', array('module' => 'default')) ); $router->addRoute( 'module_controller_action', new Zend_Controller_Router_Route(':module/:controller/:action') ); $router->addRoute( 'controller_action', new Zend_Controller_Router_Route(':controller/:action', array('module' => 'default')) );
http://hostname/user/index/index (module / controller / action) -> Works
http://hostname/index/index/key/param (controller / action / key /value) -> Works
http://hostname/user/index/index/key/param (module / controller / action / key /value) -> FAILS AGAIN! For some reason it is treating the /user/ as a "Controller" than a "Module".
Is there any way to fix this so that is behaves the same as the default routes? Ultimately I would like this combination (default routes)
http://hostname/index/index (controller / action)
http://hostname/user/index/index (module / controller / action)
http://hostname/index/index/key/param (controller / action / key /value)
http://hostname/user/index/index/key/param (module / controller / action / key /value)
to work.