【问题标题】:How to set layout for each different modules in Zend Framework 2.2如何在 Zend Framework 2.2 中为每个不同的模块设置布局
【发布时间】:2014-04-17 20:08:52
【问题描述】:

如何在 Zend Framework 2.2 中为每个不同的模块设置不同的布局文件。

例如,我想为“Admin”和“Application”模块设置不同的布局。

【问题讨论】:

    标签: zend-framework2


    【解决方案1】:

    One approach by Rob Allenconfig/autloload.php 中使用了类似的东西:

    array(
        'module_layouts' => array(
            'Application' => 'layout/application',
            'ZfcUser' => 'layout/user',
        ),
    );
    

    另一位 approach from Evan Coury - ZF2 模块系统 IIRC 的主要作者 - 在您的模块的 Module.php 文件中使用它:

    namespace MyModule;
    
    use Zend\ModuleManager\ModuleManager;
    
    class Module
    {
        public function init(ModuleManager $moduleManager)
        {
            $sharedEvents = $moduleManager->getEventManager()->getSharedManager();
            $sharedEvents->attach(__NAMESPACE__, 'dispatch', function($e) {
                // This event will only be fired when an ActionController under the MyModule namespace is dispatched.
                $controller = $e->getTarget();
                $controller->layout('layout/alternativelayout');
            }, 100);
        }
    }
    

    希望其中之一对您有用。

    【讨论】:

      猜你喜欢
      • 2013-04-04
      • 2015-03-24
      • 1970-01-01
      • 2010-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-22
      • 1970-01-01
      相关资源
      最近更新 更多