我正在尝试加载自定义布局,它加载布局但不加载模块

时间:2014-02-04 22:18:42

标签: php zend-framework2

我在这里看了几个答案,但只有一个人做了。 (在模块中加载自定义布局)。

我试过了:

$this->layout('layout/something');

但是当我看到它时它没有用:

$viewModel = new ViewModel();
$viewModel->setTemplate('layout/something');

return $viewModel;

我在模块配置中有这个:

'template_map' => array(
     'layout/something'=> __DIR__.'/../view/layout/something_layout.twig',
),

然后,当我浏览它时,它会打印模板布局,但不打印模块的视图。

任何帮助?

更新:  我发现了错误。这是因为我已经安装了ZfcTwig,这个模块基本上忽略了ZF2的布局,我必须将(在视图文件中)扩展到我将要使用的布局。但问题是这忽略了ZF2布局。

1 个答案:

答案 0 :(得分:0)

您需要使用Layout控制器插件来切换布局:

// A controller's action method that uses an alternative
// layout template.
public function indexAction() {
  //...

  // Use the Layout plugin to access the ViewModel
  // object associated with layout template.
  $this->layout()->setTemplate('layout/layout2');

  //...
}
相关问题