简体   繁体   English

将默认模板更改为“common.volt”?

[英]Change default template to 'common.volt'?

From what I understand, Phalcon uses index.phtml or index.volt in app/views as the base template for any page that doesn't have a template specified. 根据我的理解,Phalcon在app/views使用index.phtmlindex.volt作为未指定模板的任何页面的基本模板。

How can I change this to use app/views/layouts/common.volt ? 如何更改此设置以使用app/views/layouts/common.volt

It uses index.volt or index.html if the latest executed action is 'index' (indexAction in the controller). 如果最新执行的操作是'index'(控制器中的indexAction),它使用index.volt或index.html。

You can use a common layout by setting a 'template before' or a 'template after': 您可以通过设置'模板之前'或'模板之后'来使用通用布局:

https://github.com/phalcon/invo/blob/master/app/controllers/ContactController.php#L7 https://github.com/phalcon/invo/blob/master/app/controllers/ContactController.php#L7

Update August 2016 : since the above information is no longer available in the given link, adding it here: 2016年8月更新 :由于上述信息在给定链接中不再可用,请在此处添加:

public function initialize()
{
    $this->view->setTemplateBefore('your-template-name');
    $this->view->setTemplateAfter('your-template-name');
}

More info here: https://docs.phalconphp.com/en/latest/reference/views.html#using-templates 更多信息: https//docs.phalconphp.com/en/latest/reference/views.html#using-templates

When setting up the view component we need to declare $view Object like the following: 在设置视图组件时,我们需要声明$ view对象,如下所示:

$di->set('view', function () use ($config) {

    $view = new View();

    $view->setViewsDir($config->application->viewsDir);
    $view->setLayout('common');
......

using setLayout(String name) method to set default layout for app 使用setLayout(String name)方法为app设置默认布局

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM