【发布时间】:2016-11-06 15:11:06
【问题描述】:
我正在为关于 Phalcon 的视图和控制器详细信息缺乏文档问题而苦苦挣扎,
我在 index.php 中的操作是这样的,
$viewCollections = new MicroCollection() ;
$viewCollections->setHandler('BackenduiController',true) ;
$viewCollections->get('/main/index', 'index');
$app->mount($viewCollections) ;
在我的控制器中,
<?php
use Phalcon\Mvc\View;
class BackenduiController extends ControllerBase
{
public function initialize()
{
}
public function index()
{
$this->tag->setTitle('A | B');
$this->view->setTemplateAfter('nav') ;
$this->view->render(
"main","index"
);
}
}
我的观点伏特文件结构是这样的,
观看次数
--layouts
----index.volt
----nav.volt
--main
----index.volt
--index.volt
nav.volt 只是一段 nav bar html 代码,我的目的是在 main/index 页面中插入 nav bar 代码,但是如果我使用 setTemplateAfter,结果页面只是 nav 一段代码,根本不显示索引页。那么我应该如何安排代码让控制器渲染正确的页面呢?
【问题讨论】:
-
您是否在
nav.volt模板中加载视图内容。通过使用{{ content }}? -
@Timothy,谢谢,是的,在 nav.volt 内部,两行之间有 {{ content() }}。