Hi Matthew, thank you for your time and for sharing your knowledge.
If I understand ZF routing correctly, the default module routing scheme is this: http://site.com/module/controller/action This works well and I'm happy with it. Now, let me explain why I would like this: http://site.com/module/action to work as well (in case there is no controller named 'action' defined). Most of the modules I have in my application do only need single controller with multiple actions (e.g. module 'library': http://site.com/library/detail http://site.com/library/add http://site.com/library/edit http://site.com/library/delete -other modules are very similar). So I think it is unnecesary to include the 'index' controller name in all the paths (e.g. module 'library': http://site.com/library/index/detail http://site.com/library/index/add http://site.com/library/index/edit http://site.com/library/index/delete ). I believe the paths should be as simple and intuitive as possible. I agree with you that single resource should have single path and I intend to use the short one. I would also like to be routed to the default controller of the module in case the specified controller is not defined (rather than just displaying an error message). My question is: Is it possible to set the router to work like this: 1. look at first item in path. is it defined as module ? yes: remove the first item from the path and pass the path to the module no: pass the whole path to default module 2. look at first item in path. is it defined as controller ? yes: remove the first item from the path and pass the path to the controller no: pass the whole path to default controller 3. look at first item in path. is it defined as action? yes: remove the first item from the path and pass the path to the action no: pass the whole path to default action I think this setup would work best for my needs, would allow me to later easily add modules to application as well as controllers to module and actions to controller. It would also allow me to handle invalid routes on the correct level. I am a ZF newbie, so please excuse if my question was already discussed or is documented elsewhere. So far I only consumed a few ZF articles and tutorials which only used the default setup of module router. Any help appreciated. naioshi On 5/24/07, Matthew Weier O'Phinney <[EMAIL PROTECTED]> wrote:
-- naioshi cozmicboy <[EMAIL PROTECTED]> wrote (on Thursday, 24 May 2007, 05:38 AM +0200): > I would like to set my router to use IndexController in case the > controller name is invalid. > > e.g. > > 1. http://example.net/library/index/edit/id/12 (ok) > 2. http://example.net/library/edit/id/12 (error: invalid controller) > > module=library > controller=index (controller edit does not exist) > action=edit > > Is there a way to set the router to work in case 2. the same way as it > does in case 1.? > Any help appreciated. You should probably create new routes for your library module. The easiest way would be something like this: $route = new Zend_Controller_Router_Route( 'library/:action/*', array('module' => 'library', 'controller' => 'index', 'action' => 'index') ); $router->addRoute('library', $route); Of course, this means that /library/index/edit/id/12 would no longer work. If you expect both to work, you should probably rethink your routing, as this will mean 2 different paths to the same resource, which is not usually a good strategy (particularly for SEO).
