简体   繁体   English

Zend Framework 2如何使用多个模块?

[英]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. 我有一个关于Zend Framework 2的问题。我想实现多个模块。 But the view of the last Module (In this case "Home"), is displayed. 但是会显示最后一个模块(在本例中为“Home”)的视图。 I dont know why. 我不知道为什么。 Maybe someone can help me here 也许有人可以帮助我

My application.config.php 我的application.config.php

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

Everytime the "Home"-View is displayed. 每次显示“Home”-View时。 But i want the Login-View displayed. 但我希望显示登录视图。 The Controller of LoginController is called. 调用LoginController的Controller。

Make sure the template map is configured properly in your module.config.php. 确保在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. 在此示例中,模板具有两个模块的配置,但是如果您愿意,也可以为每个模块配置module.config.php,其template_map仅与该特定模块中的控制器相关。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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