设置后如何使模板失效?

How to invalidate the template once set?

问题

请告诉我如何使在 Phalcon 3 上使用 setTemplateAfter 方法设置的模板无效,以便不引用模板。


概述

当前配置由 IndexController ControllerBase 扩展。

在ControllerBase的initialize方法中,使用setTemplateAfter设置模板如下。

$this->view->setTemplateAfter('common');

在扩展的IndexController中,由于不需要template,所以执行下面的代码还是会报错

$this->view->setTemplateAfter('');

*我在想尽量不要改成ControllerBase,因为模板被别的controller使用了


错误信息

View 'layouts/' was not found in any of the views directory
#0 [internal function]: Phalcon\Mvc\View->_engineRender(Array, 'layouts/', false, true, NULL)
#1 [internal function]: Phalcon\Mvc\View->render('index', 'index')
#2 /mnt/raid/serverapps/www/lashca/public/index.php(42): Phalcon\Mvc\Application->handle()
#3 {main}

源代码

controllers/ControllerBase.php

<?php
use Phalcon\Mvc\Controller;
class ControllerBase extends Controller
{
    public function initialize()
    {
        $this->view->setTemplateAfter('common');
    }
}

controllers/IndexController.php

<?php
use Phalcon\Mvc\Controller;
class IndexController extends ControllerBase
{
    public function indexAction()
    {
        $this->view->setTemplateAfter('');
    }
}

环境

您可以通过$this->view->disable()禁用某些级别的视图渲染。

例如,如果您想禁用 "template after" 渲染,您可以这样做:

$this->view->disableLevel([
    View::LEVEL_AFTER_TEMPLATE  => true
]);

如果要禁用其他级别的视图,请选中 documentation