0
votes

I am using Zend Framework version 1.12.16. I have created two modules i.e. user and admin. I have set user module as my default module by enabling it in application.ini:

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"

resouces.modules[]=

resources.frontController.defaultModule = "user"

So, whenever users the name of the site in the url he is automatically taken to index action of indexController in user module. Similarly, I want the user to be taken to index action of the loginController of admin module whenever user types in http://example.local/admin. Can I achieve that using some settings in application.ini ?

2

2 Answers

0
votes

Zend only allows for a single definition of default module/controller/action. Behind the scenes, this creates a default route in Zend's routing system for you. Routing is the key for your problem. To match your case, you could of course do some dynamic/placeholder/whatever overkill, but a simple static route is all you need actually. This can look like that:

$route = new Zend_Controller_Router_Route_Static(
    'admin',
    array('module' => 'admin', 'controller' => 'login', 'action' => 'index')
);
$router->addRoute('admin', $route);
0
votes

Thanks Jossif!! I completely forgot this option. Adding the following method in Bootstrap.php class resolved my problem.

protected function _initRoutes()
{
    $frontController = Zend_Controller_Front::getInstance();
    $router = $frontController->getRouter();

    $route = new Zend_Controller_Router_Route_Static(
        'admin',
        array(
            'module' => 'admin',
            'controller' => 'login',
            'action' => 'index'
        )
    );

    $router->addRoute('admin', $route);
}