We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon View Simple Cache not working in Phalcon 4.0+

I had the below function in phalcon3.4 which worked fine, however, after upgrading to the phalcon4 it seems to be giving me an error in VIEW\SIMPLE and i don't see any solution for that

    /*
     * Setting up the widget view component
     */
    $di->set('widget', function () {
        $view = new \Phalcon\Mvc\View\Simple();
        $view->setViewsDir(__DIR__ . '/views/');
        $view->registerEngines(
            [
                '.volt' => function (\Phalcon\Mvc\ViewBaseInterface $view) {
                    $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $this);
                    $volt->setOptions(
                        [
                            'always'    => true,
                            'extension' => '.html',
                            'separator' => '_',
                            'stat'      => true,
                            'path' => __DIR__ . "/../../var/volt/",
                            'prefix'    => 'views_widget_',
                        ]
                    );
                    return $volt;
                }
            ]
        );
        return $view;
    });

I call this function like below

 echo $this->widget->render(
        "partials/_footer",
        array(
            "cur_year" => date("Y", time()),
        )
    );

The view file has

{# cache the sidebar by 1 hour #}
    {% cache 'footer' 3600 %}
        <div class="h-100 small">...
{% endcache %}

The error i get is

Phalcon\Mvc\View\Engine\Volt\Exception: Unknown statement 314 in
#0 [internal function]: Phalcon\Mvc\View\Engine\Volt\Compiler->statementList()
#1 [internal function]: Phalcon\Mvc\View\Engine\Volt\Compiler->compileSource()
#2 [internal function]: Phalcon\Mvc\View\Engine\Volt\Compiler->compileFile()
#3 [internal function]: Phalcon\Mvc\View\Engine\Volt\Compiler->compile()
#4 [internal function]: Phalcon\Mvc\View\Engine\Volt->render()
#5 [internal function]: Phalcon\Mvc\View\Simple->internalRender()

From a cursory read through the documentation, it would appear Phalcon 4.x no longer has caching functionality like this.

https://github.com/phalcon/cphalcon/issues/14907#issuecomment-598742013

edited Dec '20

I'm trying to load a template in PhalconPHP (v 2.0.13), but even the simplest example ... Here is a working example of declaring a dependency injectable view ... loaded from config in this case $view->registerEngines(array( '.volt' ... your webserver has rights to read views and R/W rights for cache directory myprepaidcenter