【问题标题】:Change default template to 'common.volt'?将默认模板更改为“common.volt”?
【发布时间】:2013-11-11 19:46:13
【问题描述】:

据我了解,Phalcon 使用app/views 中的index.phtmlindex.volt 作为没有指定模板的任何页面的基本模板。

如何将其更改为使用app/views/layouts/common.volt

【问题讨论】:

标签: php phalcon volt


【解决方案1】:

如果最新执行的动作是'index'(控制器中的indexAction),它使用index.volt或index.html。

您可以通过设置“模板之前”或“模板之后”来使用通用布局:

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

2016 年 8 月更新:由于给定链接中不再提供上述信息,请在此处添加:

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

更多信息在这里:https://docs.phalconphp.com/en/latest/reference/views.html#using-templates

【讨论】:

  • 是的,但这需要手动进入每个控制器并进行设置,而且我很确定有一种情况它不起作用。无论如何, $view->setMainView('common') 是我正在寻找的。谢谢!
【解决方案2】:

在设置视图组件时,我们需要像下面这样声明 $view 对象:

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

    $view = new View();

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

使用 setLayout(String name) 方法为应用设置默认布局

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-11
    • 2013-03-15
    • 1970-01-01
    • 2019-03-14
    • 2013-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多