Zend Framework 2.2 で異なるモジュールごとに異なるレイアウト ファイルをセットアップする方法。
たとえば、「管理」モジュールと「アプリケーション」モジュールで異なるレイアウトが必要です。
Zend Framework 2.2 で異なるモジュールごとに異なるレイアウト ファイルをセットアップする方法。
たとえば、「管理」モジュールと「アプリケーション」モジュールで異なるレイアウトが必要です。
Rob Allen による 1 つのアプローチでは、次のようなものを使用しますconfig/autloload.php
。
array(
'module_layouts' => array(
'Application' => 'layout/application',
'ZfcUser' => 'layout/user',
),
);
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);
}
}
うまくいけば、これらのいずれかがあなたのために働くでしょう。