Zend_Controller_Router_Rewrite - Rewriting from one module to another
I am trying something seemingly开发者_运维技巧 simple in my Zend Framework Project: I want to rewrite one module to another, so that the same code is being used for what seem to the user to be two different modules.
So the URL http://www.mydomain.net/subadmin/anyController/anyAction is rewritten to http://www.mydomain.net/admin/anyController/anyAction
The user should still see http://www.mydomain.net/subadmin/anyController/anyAction though.
I would not have thought this should be too hard, but I cannot figure it out.
Any help appreciated.
Add a route that performs the mapping.
Using an .ini file to specify the mapping:
routes.subadmin.type = "Zend_Controller_Router_Route"
routes.subadmin.route = "subadmin/:controller/:action"
routes.subadmin.defaults.module = "admin"
routes.subadmin.defaults.controller = "index"
routes.subadmin.defaults.action = "index"
Alternatively, using code in Bootstrap.php
:
protected function _initRoutes()
{
$this->bootstrap('frontcontroller');
$front = $this->getResource('frontcontroller');
$router = $front->getRouter();
$route = new Zend_Controller_Router_Route('subadmin/:controller/:action', array(
'module' => 'admin',
'controller' => 'index',
'action' => 'index',
));
$router->addRoute($route);
}
精彩评论