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

HMVC & volt

Hello. When i found HMVC implementation in Phalcon i was excited. I try add volt template to child controller, but this don't work.

I think it's possible to add execution view in controller, but in my mind its weak! Did somebody find better way to implementation HMVC with working volt templates?

The configuration must be in module.php, here you configure volt with each module, this file become bootstrap file for you module. all configuration for your model must be here. public/index ->is for general configuration.

Phalcon example is single module application without module.php. In these example, config is global.

Im using this example: https://github.com/phalcon/mvc/tree/master/hmvc

I change

  $di['view'] = function() {
      $view = new View();
      $view->setViewsDir('../app/views/');
      return $view;
  };

To

    $di['view'] = function () {

        $view = new Phalcon\Mvc\View();

        $view->setViewsDir('../app/views/');

        $view->registerEngines(array(
            '.volt' => function ($view, $di) {

                $volt = new Phalcon\Mvc\View\Engine\Volt($view, $di);

                $volt->setOptions(array(
                    'compiledPath' => '../app/cache/',
                    'compiledSeparator' => '_',
                    'compileAlways' => true
                ));

                return $volt;
            },
            '.phtml' => 'Phalcon\Mvc\View\Engine\Php'
        ));

        return $view;
    }, true);

My SayController

    class SayController extends Controller
    {

        public function helloAction()
        {
            //return new Response('hello there');
        }

    }

And add app/views/say/hello.volt

It seems to me that the problem is the use of dispatcher instead of a application class. Did dispacher initialize temple engine?

Any idea?

edited Apr '15

This better example, https://github.com/phalcon/mvc/tree/master/multiple-volt, other error could be the path. .... dispatcher handle routing, this not initialize to volt. Di initialize volt with the "view"

yeah, this the problem, your view folder is not in "../app/views/", Could you show the struct of your proyect?

https://github.com/pwoszczyk/phalcon-hmvc-volt

Volt path is correct. When sending request index/index receive response with null. When sending request say/hello receive correct response.