2016-11-06 103 views
0

我挣扎上视图和控制器约尔康细节缺乏文档问题,如何在渲染特定视图时插入布局伏特?

我在做什么的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只是一个html代码的导航栏片段,我的目的是在主/索引页面中插入导航条形码,但是如果我使用setTemplateAfter,结果页面只是导航片段代码,根本不显示索引页面。那么,我应该如何安排代码来使控制器呈现正确的页面?

+0

你加载你的观点在'nav.volt'模板的内容。通过使用'{{content}}'? – Timothy

+0

@蒂莫西,谢谢,是的,在nav.volt中,行之间有{{content()}}。 –

回答

0

我正在做的是使用include。

将这个在index.volt在导航应该是

{% include "layouts/nav.volt" %} 

应该做的伎俩