How do I change the routing in ini file, of Zend framework, to point to another controller?
Say if I want to change the router. If I type example.com/controller1/action1, I want it开发者_JAVA百科 to go to example.com/controller2/action2 How do I set this up in the ini file?
If you just want to access controller2 action2 from the url controller1/action1, then the following should do the trick :
First, create an INI file with the following content (/configs/routes.ini) :
[production]
routes.controller1_action1.route = "controller1/action1"
routes.controller1_action1.defaults.controller = "controller2"
routes.controller1_action1.defaults.action = "action2"
Then add the following code snippet to your bootstrap :
protected function _initRewrite() {
$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routes.ini', 'production');
$router->addConfig($config,'routes');
}
Following up on wimvds' post - if applicable, perhaps you also need to specify the module? Also, I'm not sure if this will make a difference, but I also prefix my routes with 'resources.router'.
So, the full set might be :-
resources.router.routes.controller1_action1.route = "controller1/action1"
resources.router.routes.controller1_action1.defaults.controller = "controller2"
resources.router.routes.controller1_action1.defaults.action = "action2"
resources.router.routes.controller1_action1.defaults.module = "module2"
Hope that helps.
精彩评论