ZF Tip: Don’t use ‘index’ as a module name.

I’ve been using Zend Framework for a while and when I do my own sites things always work as expected.  But a couple of times in the past I’ve had the honor of working on other sites with other people that have lead me to a few ‘wtf?’ issues.

The most recent one was as to why the shorter urls ie: “/index/pants” would not work.  It would always complain and blow up that the controller ‘pants’ doesn’t exist.  Even though I know for a fact that I want the index controller in the default module and the action ‘pants’…

The problem with naming your default, or any module ‘index’ is the way ZF matches and routes the request.  If you have a module called ‘index’ then any request that begins with ‘/index’ will get routed to it.  Even if this isn’t what you want.  Typically  when I have actions like ‘about’ or ‘contact’, they reside in my default module and are easily accessed by ‘/index/about’ or ‘/index/contact’ – when a module exists called ‘index’ these shorter links don’t work and I’d need ‘/index/index/about’ or ‘/index/index/contact’ – these suck and thus you should never have ‘index’ as a module name.

The point: If your default module has to be in the URL to access these default actions, you’re not using the ‘default’ module properly.

Published by Darryl Clarke

random text goes here, i guess