Php 如何在zf2中包含文件phtml
我正在使用Zend Framework 2。我想将文件phtml包含到其他phtml中。以下是我的文件夹结构:Php 如何在zf2中包含文件phtml,php,zend-framework2,Php,Zend Framework2,我正在使用Zend Framework 2。我想将文件phtml包含到其他phtml中。以下是我的文件夹结构: ::module ->AppFeeder ->config ->src ->AppFeeder ->Controller ->FeederController.php ->view ->app-feeder -&
::module
->AppFeeder
->config
->src
->AppFeeder
->Controller
->FeederController.php
->view
->app-feeder
->feeder
->index.phtml
->layout
->menu.phtml
我想要index.phtml包含文件菜单.phtml。如何包含该文件?您能帮助我吗?通过控制器操作,您可以将.phtml作为子视图包括在内,如下所示
public function indexAction() {
// This will by default use the index.phtml file from the feeder directory
$view = new ViewModel();
$menu = new ViewModel();
$menu->setTemplate('app-feeder/layout/menu.phtml');
$view->addChild($menu, 'menu');
return $view;
}
然后可以使用以下命令将其包含在index.phtml文件中
<?php echo $this->menu; ?>
您有三种方法:
- 分部
- 子视图
- 查看帮助程序
无论如何,我建议您将布局文件夹重命名为partial。Layout是所有视图的模板,在zf2中有特殊处理。Layout是子文件夹?是。文件夹布局是app feeder的子文件夹。这是错误的吗?尝试,包括“layout/menu.phtml”;