简体   繁体   中英

Zend Framework 2 How to use multiple Modules?

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.

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',
    )
 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM