So I know that you can set a custom default action in Zend Framework in the application.ini
:
resources.frontController.defaultAction = "something"
But what if I want this default action to be contingent on the controller? So controller A
's default action will be B
, controller C
's default action will be D
, etc how do I configure the controllers to take these default action parameters? What piece of code is needed and where should I place them?
You can add in your Bootstrap.php something like this:
An alternative approach to handling lots of routes could be to have the controller decide what he wants to do:
My GUESS is, that this approach is faster than adding dozens of custom routes. But that's just a guess, nothing tested here.
By default you can only say in general what the default action for a controller is. If you want to dispatch a certain controller and action under a specific URI, you can do this by using routes.
There is a default route which you probably use in your application right now. You can add additional routes from the application.ini or otherwise create a frontController plugin to inject routes into the router. The former is much easier, the latter gives you more abilities, for example to load routes based on entries in the database.
The routes in application.ini are good explained in the manual of ZF. It comes down to these four lines per route:
Here it is possible to specify the default action by
defaults.action
. For parameters in routes, the section about the Zend_Controller_Router_Route type explains it pretty well.The other option is a frontController plugin. This class can hook into different parts of the process and this system is very powerful if used correctly. It is probably not required for your question, but you might want to have a look at the manual where there is a page about plugins and a section how to load these plugins in your application.ini.