Call to a controller from another controller


#1

Hi everyone, I have a homecontroller, but I need to create one sub-controller, or a class that will build the menu bar, and I need to create another sub-controller or class that will build the main homepage that will contains all the direct access for each type of user, the main homecontroller will call to those sub controllers to return all resources (menu bar and homepage) to homeview.

How can I do that?


#2

Hey @Mathias.gmz! :wave:

Short answer: You cannot.

Long answer:

The UI composition should happened in the templating engine and not in the Controller. Also, if you have logic that should be used in multiple controllers you may want to extract it to a Service.


#3

Hello @romain.lanz, thank you for reply, but i want to split my homecontroller in two parts, one controller manage the menu bar, and the other controller manage the view of the home page, finally, the homecontroller sends to the view all the resources… for a dinamic view
Because each type of user will can see a customized menu bar and shortcuts according to him work


#4

For this use case, you may want to create a view globals that provides information and then your partials that render the menu will use it.


#5

Lets see it this way

Controller job is to handle a single HTTP request and return response for it, now of course one HTTP request cannot have 2 responses ( menu bar and main app )

What you need is to make this formation at the view level