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

Volt inside simple view error

     $simple_view = new \Phalcon\Mvc\View\Simple();
      $simple_view->registerEngines(
          [
              ".phtml" => "Phalcon\\Mvc\\View\\Engine\\Php",
              ".volt"  => "Phalcon\\Mvc\\View\\Engine\\Volt"
          ]
      );
      //$simple_view->getRegisteredEngines();
      $simple_view->setViewsDir( __DIR__ . '/../../Templates/Phalcon/');
      echo  $simple_view->render('Models');

hello every body

when i registering engines into simple view, i have this error:

A dependency injector container is required to obtain the application services

How to use volt engine inside simple view?



85.5k
Accepted
answer

you need to register it as a service, just use Shared false, like you register your router etc...


$di->set("simpleView", function(){

    view = new view..

    register ...

    return $view;

}, false );

....

//in controller 

$this->getDI()->get("simpleView")->render ...