views:

73

answers:

1

How do I eliminate the need for the "Controller" suffix in the filename of a Zend Framework controller? It just gets tiresome to keep typing that suffix in when creating controllers, and meanwhile the file is already in a controllers folder so it's superfluous.

For instance, by default the homepage on a site goes to "controllers/IndexController.php". What if I want it to go to "controllers/Index.php"?

+5  A: 

The latter portion of the class name is hardcoded to "Controller" in Zend_Controller_Dispatcher_Abstract::formatControllerName().

To change it, you'd have to create a custom Dispatcher class that implements Zend_Controller_Dispatcher_Interface and override the formatControllerName() function. Then assign an instance of your new Dispatcher to the front controller in your bootstrap script with $frontController->setDispatcher() before you call dispatch().

Why would you need to change the format of a controller class name anyway? It's not like that PHP file appears in a request URL anywhere.

Sounds like you're bikeshedding.

Bill Karwin
Eh, its an interesting thought experiment at least. When originally looking at ZF, I found the fact that controllers/models/etc broke from the traditional naming scheme (PEAR style, where it goes from least-to-most-specific) pretty odd, where the rest of ZF followed that. So, if you're stuck wanting to name your controllers like MyApp_Controller_Action_Index - you can, with the above.
Justin