Hanno
Hanno

Reputation: 43

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.

Upvotes: 0

Views: 460

Answers (1)

David Weinraub
David Weinraub

Reputation: 14184

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);
}

Upvotes: 1

Related Questions