1
如何在Zend Framework 2.2中为每个不同的模块设置不同的布局文件。如何在Zend Framework 2.2中为每个不同的模块设置布局2.2
例如,我想为'Admin'和'Application'模块设置不同的布局。
如何在Zend Framework 2.2中为每个不同的模块设置不同的布局文件。如何在Zend Framework 2.2中为每个不同的模块设置布局2.2
例如,我想为'Admin'和'Application'模块设置不同的布局。
One approach by Rob Allen使用在config/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);
}
}
希望其中的一个会为你工作。