Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Can a partial have a controller ?

I cannot find an equivalent of something I used before on Sf1, the component, which is a controler and a partial view bundled as a whole (meaning of "component" differs in Sf1 and Sf2+). Let me explain :

Let suppose you have a global layout with a big side menu on the left. In order to have a clean and easy readable layout code you will use include/partial, for instance with volt :

{% include 'partials/sidemenu.volt' %}

But let suppose sidemenu is a bit complex to build, but never changes according to the context : side menu is always the same, whatever the page.

In this case, the ideal for me is to put logic into a kind of controller to build my menu and then render it into the partial. Can Phalcon do things like that ?


Finally I managed this issue with a service which acted as a "sideMenuManager", whose role is to compute the right values to put in view thanks to dedicated methods. In the view the service with its methods is reachable by typing inside braces


So far I consider this issue solved, unless someone has a better answer.

Using service is good idea. this keyword in view is not needed as far as i remember.


Indeed, after having tested it, it seems that "this" keyword can be omitted. Thanks for this information :)