Question

I have a question about the Zend Framework 2. I want to implement more than one Modules. But the view of the last Module (In this case "Home"), is displayed. I dont know why. Maybe someone can help me here

My application.config.php

'modules' => array(
    "Login",
    "Home",
),

Everytime the "Home"-View is displayed. But i want the Login-View displayed. The Controller of LoginController is called.

Was it helpful?

Solution

Make sure the template map is configured properly in your module.config.php. In this example the template has the configs for both modules, however you could also have a module.config.php for each module if you so desired, with its template_map pertaining only to the controllers within that specific module.

'view_manager' => array(
    'display_not_found_reason' => true,
    'display_exceptions'       => true,
    'doctype'                  => 'HTML5',
    'not_found_template'       => 'error/404',
    'exception_template'       => 'error/index',
    'template_map'             => array(
        'Login/some_controller/index' => __DIR__ . '/path/to/view/file', 
        'Home/some_controller/index'  => __DIR__ . '/path/to/view/file'
    'template_path_stack' => array(
        __DIR__ . '/../view',
    ),
)

Now your controller invokables

'controllers' => array(
    'invokables' => array(
        'Home\Controller\Index' => 'Home\Controller\IndexController',
        'Login\Controller\Ajax' => 'Application\Controller\AjaxController',
    )
 )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top