View Cache Location

Is there a way to put the view cache in another directory? It bothers me to edit files and sometimes I open the wrong one, eg:

  - file.volt
  - file.volt.php
  - second.volt
  - second.volt.php
    $di->set('view', function() {
        $view = new \Phalcon\Mvc\View();
        $view->setViewsDir('../app/views/');
        $view->registerEngines([
            ".volt" => 'Phalcon\Mvc\View\Engine\Volt'
        ]);
        return $view;
    });


7.2k

See documentation. You can assign any directory in which the server has write permissions.

$di->set('view', function () {
    $view = new \Phalcon\Mvc\View();
    ...
    $view->registerEngines([
        '.volt' => function ($view, $di) {
            $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
            $volt->setOptions([
                'compiledPath' => __DIR__.'/path/to/cache/', // <-- This is where you can set the cache path
                'compiledSeparator' => '_',
            ]);
            return $volt;
        },
        '.phtml' => 'Phalcon\Mvc\View\Engine\Php'
    ]);
});

Thanks! I couln't find the setOptions parameters, I figured there would be a cachePath() method or something :)