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

Hierarchy view Question

Well I’m studying about hierarchy view and I don’t understand why I must put a file in /view/layouts/ for each controller.

I don’t understand well, but I think the execute order is:

1-. controller /view/layouts/users.volt (this have only content )

2-. Template (if exist) /view/layouts/admin.volt // I use this template to re-use the admin panel.

3-. Action /view/users/index

4-. main (/view/index)

Now the examples INVO and VOKURO have not this files and working so well, what is the difference?



43.9k
Accepted
answer
edited May '15

Hi,

the default behavior of view rendering hierarchy of a phalcon MVC application is explained here.

So far I can see, Invo use this default rendering system. Vokuro use a main views/index.volt and two templates in views/layouts : public.volt and private.volt.


// in PermissionsController.php line 18 in indexAction()
$this->view->setTemplateBefore('private');

// in IndexController line 16 in indexAction()
$this->view->setTemplateBefore('public');

If template apply to all controller actions, you may put the code above in initialize() method (or use default controller layout file, eg layouts/permissions.volt). If many controllers should use the same layout, they can extend from (in vokuro context) a PrivateController wich initialize the template.



17.7k

but to create the privatecontroller others inherit from him?



43.9k

// PrivateController

class PrivateController extends BaseController {....}

// PermissionsController

class PermissionsController extends PrivateController{...}


17.7k

thank's... you solved my question