Zend framework2 zf2中不同模块的不同布局
如何为不同的模块设置不同的布局。我已将布局用于操作,即Zend framework2 zf2中不同模块的不同布局,zend-framework2,Zend Framework2,如何为不同的模块设置不同的布局。我已将布局用于操作,即 public function indexAction(){ $this->layout()->setTemplate('layout/manager'); return new ViewModel(); } 它工作正常。但是我希望它是这个模块的默认值。所以我在构造中使用了它。但是这种布局在构造中不起作用。有人能告诉我如何在没有控制器操作的情况下使用此模块布局吗。 提前感谢。有一个模块可以为每个模块提供
public function indexAction(){
$this->layout()->setTemplate('layout/manager');
return new ViewModel();
}
它工作正常。但是我希望它是这个模块的默认值。所以我在构造中使用了它。但是这种布局在构造中不起作用。有人能告诉我如何在没有控制器操作的情况下使用此模块布局吗。
提前感谢。有一个模块可以为每个模块提供不同的布局
非常容易使用,只需遵循自述说明即可有一个模块,每个模块具有不同的布局
非常容易使用,只需遵循自述说明即可有一个模块,每个模块具有不同的布局
非常容易使用,只需遵循自述说明即可有一个模块,每个模块具有不同的布局
非常易于使用,只需遵循自述文件指示假设您有一个名为管理的模块 步骤1在Module.php文件中添加以下行: 在第一个函数中需要特别注意的是onBootstrap函数,添加必要的行,而不是覆盖它 module/Administration/module.php
public function onBootstrap($e) {
// Register a dispatch event
$app = $e->getParam('application');
$app->getEventManager()->attach('dispatch', array($this, 'setLayout'));
}
public function setLayout($e) {
$matches = $e->getRouteMatch();
$controller = $matches->getParam('controller');
if (false === strpos($controller, __NAMESPACE__)) {
// not a controller from this module
return;
}
// Set the layout template
$viewModel = $e->getViewModel();
if ($viewModel->getTemplate() === 'layout/layout') {
$viewModel->setTemplate('layout/administration');
}
}
'view_manager' => array(
'template_map' => array(
'layout/administration' => __DIR__ . '/../view/layout/layout.phtml',
),
'template_path_stack' => array(
'administration' => __DIR__ . '/../view',
),
),
步骤2在module.config.php文件中添加以下行:
module/Administration/config/module.config.php
public function onBootstrap($e) {
// Register a dispatch event
$app = $e->getParam('application');
$app->getEventManager()->attach('dispatch', array($this, 'setLayout'));
}
public function setLayout($e) {
$matches = $e->getRouteMatch();
$controller = $matches->getParam('controller');
if (false === strpos($controller, __NAMESPACE__)) {
// not a controller from this module
return;
}
// Set the layout template
$viewModel = $e->getViewModel();
if ($viewModel->getTemplate() === 'layout/layout') {
$viewModel->setTemplate('layout/administration');
}
}
'view_manager' => array(
'template_map' => array(
'layout/administration' => __DIR__ . '/../view/layout/layout.phtml',
),
'template_path_stack' => array(
'administration' => __DIR__ . '/../view',
),
),
这些更改仅在您想要区分的模块中需要。假设您有一个名为管理的模块 步骤1在Module.php文件中添加以下行: 在第一个函数中需要特别注意的是onBootstrap函数,添加必要的行,而不是覆盖它 module/Administration/module.php
public function onBootstrap($e) {
// Register a dispatch event
$app = $e->getParam('application');
$app->getEventManager()->attach('dispatch', array($this, 'setLayout'));
}
public function setLayout($e) {
$matches = $e->getRouteMatch();
$controller = $matches->getParam('controller');
if (false === strpos($controller, __NAMESPACE__)) {
// not a controller from this module
return;
}
// Set the layout template
$viewModel = $e->getViewModel();
if ($viewModel->getTemplate() === 'layout/layout') {
$viewModel->setTemplate('layout/administration');
}
}
'view_manager' => array(
'template_map' => array(
'layout/administration' => __DIR__ . '/../view/layout/layout.phtml',
),
'template_path_stack' => array(
'administration' => __DIR__ . '/../view',
),
),
步骤2在module.config.php文件中添加以下行:
module/Administration/config/module.config.php
public function onBootstrap($e) {
// Register a dispatch event
$app = $e->getParam('application');
$app->getEventManager()->attach('dispatch', array($this, 'setLayout'));
}
public function setLayout($e) {
$matches = $e->getRouteMatch();
$controller = $matches->getParam('controller');
if (false === strpos($controller, __NAMESPACE__)) {
// not a controller from this module
return;
}
// Set the layout template
$viewModel = $e->getViewModel();
if ($viewModel->getTemplate() === 'layout/layout') {
$viewModel->setTemplate('layout/administration');
}
}
'view_manager' => array(
'template_map' => array(
'layout/administration' => __DIR__ . '/../view/layout/layout.phtml',
),
'template_path_stack' => array(
'administration' => __DIR__ . '/../view',
),
),
这些更改仅在您想要区分的模块中需要。假设您有一个名为管理的模块 步骤1在Module.php文件中添加以下行: 在第一个函数中需要特别注意的是onBootstrap函数,添加必要的行,而不是覆盖它 module/Administration/module.php
public function onBootstrap($e) {
// Register a dispatch event
$app = $e->getParam('application');
$app->getEventManager()->attach('dispatch', array($this, 'setLayout'));
}
public function setLayout($e) {
$matches = $e->getRouteMatch();
$controller = $matches->getParam('controller');
if (false === strpos($controller, __NAMESPACE__)) {
// not a controller from this module
return;
}
// Set the layout template
$viewModel = $e->getViewModel();
if ($viewModel->getTemplate() === 'layout/layout') {
$viewModel->setTemplate('layout/administration');
}
}
'view_manager' => array(
'template_map' => array(
'layout/administration' => __DIR__ . '/../view/layout/layout.phtml',
),
'template_path_stack' => array(
'administration' => __DIR__ . '/../view',
),
),
步骤2在module.config.php文件中添加以下行:
module/Administration/config/module.config.php
public function onBootstrap($e) {
// Register a dispatch event
$app = $e->getParam('application');
$app->getEventManager()->attach('dispatch', array($this, 'setLayout'));
}
public function setLayout($e) {
$matches = $e->getRouteMatch();
$controller = $matches->getParam('controller');
if (false === strpos($controller, __NAMESPACE__)) {
// not a controller from this module
return;
}
// Set the layout template
$viewModel = $e->getViewModel();
if ($viewModel->getTemplate() === 'layout/layout') {
$viewModel->setTemplate('layout/administration');
}
}
'view_manager' => array(
'template_map' => array(
'layout/administration' => __DIR__ . '/../view/layout/layout.phtml',
),
'template_path_stack' => array(
'administration' => __DIR__ . '/../view',
),
),
这些更改仅在您想要区分的模块中需要。假设您有一个名为管理的模块 步骤1在Module.php文件中添加以下行: 在第一个函数中需要特别注意的是onBootstrap函数,添加必要的行,而不是覆盖它 module/Administration/module.php
public function onBootstrap($e) {
// Register a dispatch event
$app = $e->getParam('application');
$app->getEventManager()->attach('dispatch', array($this, 'setLayout'));
}
public function setLayout($e) {
$matches = $e->getRouteMatch();
$controller = $matches->getParam('controller');
if (false === strpos($controller, __NAMESPACE__)) {
// not a controller from this module
return;
}
// Set the layout template
$viewModel = $e->getViewModel();
if ($viewModel->getTemplate() === 'layout/layout') {
$viewModel->setTemplate('layout/administration');
}
}
'view_manager' => array(
'template_map' => array(
'layout/administration' => __DIR__ . '/../view/layout/layout.phtml',
),
'template_path_stack' => array(
'administration' => __DIR__ . '/../view',
),
),
步骤2在module.config.php文件中添加以下行:
module/Administration/config/module.config.php
public function onBootstrap($e) {
// Register a dispatch event
$app = $e->getParam('application');
$app->getEventManager()->attach('dispatch', array($this, 'setLayout'));
}
public function setLayout($e) {
$matches = $e->getRouteMatch();
$controller = $matches->getParam('controller');
if (false === strpos($controller, __NAMESPACE__)) {
// not a controller from this module
return;
}
// Set the layout template
$viewModel = $e->getViewModel();
if ($viewModel->getTemplate() === 'layout/layout') {
$viewModel->setTemplate('layout/administration');
}
}
'view_manager' => array(
'template_map' => array(
'layout/administration' => __DIR__ . '/../view/layout/layout.phtml',
),
'template_path_stack' => array(
'administration' => __DIR__ . '/../view',
),
),
这些更改仅在要区分的模块中需要