2

I have the following controllers in my modules..

UserController.php AdminUserController.php

Now the route for admin controller goes to: module/admin-user/ (default behaviour)

How do I make a route so all admin- will be changed to:

/admin/module/user

1 Answer 1

2

You will have to write a custom route.

In code:

$front = Zend_Controller_Front::getInstance(); $router = $front->getRouter(); $route = new Zend_Controller_Router_Route( 'admin/:module/user', array('controller' => 'admin-user')); $router->addRoute('module-admin-router', $route); 

In a .ini file (I like to keep mine separate from application.ini):

[routes] routes.module-admin-router.type = "Zend_Controller_Router_Route" routes.module-admin-router.route = "archive/:module/user" routes.module-admin-router.defaults.controller = "admin-user" 

Then you will have to bootstrap that application section to enable the routes;

protected function _initRoutes () { // setup routes here. $front = $this->getResource('frontcontroller'); $router = $front->getRouter(); $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routes.ini', 'routes'); $router->addConfig($config->routes); } 

This route will match any admin/module/user request and send it to the AdminUserController within the matching module.

Something like that should work. Now if things get really complicated, you'll probably need to dig into the regex router - but this is as simple as I can think of it needing to be.

Sign up to request clarification or add additional context in comments.

3 Comments

Is it possible to do it in the application.ini with the regex router :P as i need all modules to be routed the same way.
Thanks but I cannot seem to get variables in the used controller.. example: resources.router.routes.module-admin-router.route = "admin/:module/:controller/:action" resources.router.routes.module-admin-router.defaults.controller = "admin-:controller" Does not work :(
It will not work. You can't inject variables like that, unfortunately. This route probably needs to be converted into a Regex route in order to do more complicated matching.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.