Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

$this->view->disable() still load compiled layout

Hello, I made a dynamic robots.txt controller and I have this code:

    public function robotsAction()
        $this->response->setHeader("Content-Type", "text/plain");
        $this->response->setContent("User-agent: *");

Problem is that in errorlog I see: "2016/10/25 22:21:47 [error] 22649#0: 9295 FastCGI sent in stderr: "PHP message: PHP Notice: Undefined variable: location in /var/www/cache/volt/varwwwmainappviewsindex.volt.php on line 223"

So, view is still processed but not rendered, is any way to disable this ? Thanks!


Yes, I did check, but I don't want pemanent disable, I added disable render code in view service and is true that it won't compile anymore but ... for all controllers. I need this only for one controller/action, I tried several methods but layout is still compiling.

edited Oct '16

Change your code to:

$this->response->setHeader("Content-Type", "text/plain");
return $this->response->setContent("User-agent: *");

Even disable is not needed.

Also you sure that this action is hitted and there is no some forward or something ? /var/www/cache/volt/varwwwmainappviewsindex.volt.php auto rendering would never render index.volt.php from robotsAction anyway


Thanks for response, but I still see template notices (they are still loaded). This is my view service

$di->set('view', function () {
    $config = $this->getConfig();
    $view = new View();
        '.volt' => function ($view) {
            $config = $this->getConfig();
            $volt = new VoltEngine($view, $this);
                'compiledPath' => $config->application->cacheDir . 'volt/',
                'compiledSeparator' => '_'
            $compiler = $volt->getCompiler();
            $compiler->addFunction("shuffle", "shuffle");
                function () {
                    return 'Vokuro\Utils\MyTags::lang()';
            return $volt;

    $eventsManager = new Phalcon\Events\Manager();
    $eventsManager->attach("view", new \Vokuro\Utils\RenderView());

    return $view;
}, true);

No matter level of rendering set in method, beforeRender is still called. With: this code added in service, no layout is loaded, only controller/action block.

edited Oct '16

Better show dispatcher code. Check if this action is even executed by die(); on beginning or xdebug breakpoint. The code i wrote for 100% can't hit view anywhere internally. I have like most of action returning json and im not disabling view anywhere. To prove it:

As you see, view is hitted only in else condition. If you return response object from action i posted view is not even hitted.

 * Dispatcher use a default namespace
$di->set('dispatcher', function () {
    $dispatcher = new Dispatcher();

    $eventsManager = new Manager();
    $eventsManager->attach("dispatch:beforeDispatchLoop", new Vokuro\Locale\Localisation());

    $eventsManager->attach("dispatch:beforeException", function($event, $dispatch, $exception) {
        if ($event->getType() == 'beforeException') {
            switch ($exception->getCode()) {
                case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                        'controller' => 'index',
                        'action' => 'notFound'
                    return false;

    return $dispatcher;

Added first line in robotsAction - die(); - still rendering in errorlog. /var/www/cache/volt/varwwwmainappviewsindex.volt.php - this is main layout containing only header/{{ content() }}/footer

edited Oct '16

As i posted already. The code above should work for 100%. Are you sure you checked my code ?

As you see here - if response object is returned from action else(which can call render is not even hitted).

If it's not working then problem is somewhere else, possible some forward, or you just call render yourself, not robotsAction, what's the content of Vokuro\Locale\Localisation ?

Also if this still rendering in errorlog it means that problem is somewhere BEFORE robotsAction, because render from robotsAction could only happen if nothing is returned from controller action.

Also you should use your own namespace instead of Vokuro :D


LOL, this caused the problem:

class ControllerBase extends Controller
    public function initialize()

I deleted $this->assets code and rendering level worked. Is this a bug ?

edited Oct '16

No it's not. Assets manager is not calling view anywhere. Problem must be somewhere else.


Problem was the buggy favicon .... missing and no rules in nginx. Thanks for help.