我有 2 个模块,我需要为每个模块使用不同的布局,但所有模块总是使用第二个加载模块的布局。
应用程序.config.php:
return array(
// This should be an array of module namespaces used in the application.
'modules' => array(
'news',//in this module use Application layout
'Application',
),
我有 2 个模块,我需要为每个模块使用不同的布局,但所有模块总是使用第二个加载模块的布局。
应用程序.config.php:
return array(
// This should be an array of module namespaces used in the application.
'modules' => array(
'news',//in this module use Application layout
'Application',
),
您可以使用EdpModuleLayouts。它是一个 ZF2 模块,允许您为每个模块配置不同的布局。它的用法很简单:
EdpModuleLayouts
在application.config.php
文件中启用模块:
'modules' => array(
'EdpModuleLayouts', //<---add this line
'News',
'Application',
),
在两个模块之一的文件中定义每个模块的布局module.config.php
,例如在应用程序模块中。在这里,我们设置了两种布局:news/layout
新闻模块和应用程序layout/layout
模块:
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'XHTML1_TRANSITIONAL',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'news/layout' => __DIR__ . '/../../News/view/layout/admin-layout.phtml',
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
'application' => __DIR__ . '/../view',
'news' => __DIR__ . '/../../News/view',
),
),
'module_layouts' => array(
'Application' => 'layout/layout',
'News' => 'news/layout',
),
设置在您的{MyNewModule}/Module.php
.
namespace {MyNewModule};
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\Mvc\ModuleRouteListener;
use Zend\ModuleManager\ModuleManager;
use Zend\Mvc\MvcEvent;
创建一个新的方法初始化。
public function init(ModuleManager $manager){
$events = $manager->getEventManager();
$sharedEvents = $events->getSharedManager();
$sharedEvents->attach(__NAMESPACE__, 'dispatch', function($e) {
$controller = $e->getTarget();
$controller->layout('layout/***customFile.phtm***');
}, 100);
}
F5,给你的浏览器充值。
我也有同样的情况并像这样解决它:
有了模块login
,application
我所做的就是确定这样的布局global.php
:
return array(
'module_layouts' => array(
'Application' => 'layout/layout.phtml',
'Login' => 'layout/login.phtml'
),
);
现在您应该在视图布局登录中创建一个文件夹,login.phtml
现在在登录模块的配置中。Module.config.php
'view_manager' => array(
'template_path_stack' => array(
'Login' => __DIR__ . '/../view',
),
)
;
这应该运行你。