【问题标题】:How to insert the layout volt when rendering a specific view?渲染特定视图时如何插入布局伏特?
【发布时间】: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() }}。

标签: php view phalcon


【解决方案1】:

我正在做的是使用包含。

把它放在应该导航的 index.volt 中

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

应该做的伎俩

【讨论】:

    猜你喜欢
    • 2013-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-26
    • 1970-01-01
    • 1970-01-01
    • 2018-10-21
    相关资源
    最近更新 更多