The situation is such that, having experience with bitrix and the internal engine of the company, I got used to the fact that the action of the controller (or its similarity as a component) is calmly called at any point of any template and any specified template of this controller is launched.

At the same time in Yii I do not find anything like that.

Question: So, if I need in a layout in addition to displaying $ content of the requested controller (let's call it main) display other dynamic information (let's call it additional) , it is necessary to create a widget for it or, alternatively, create another action where the common ones will be passed results to display basic and additional information?

For example: On the main page, in addition to the text of the main page, you need to display a list of the latest news, random news and a feedback form, all of which also exist as separate pages with separate controllers.

    1 answer 1

    That's right, in Yii2, such tasks are solved through widgets. If you need to get access to the controller from the layout or view, you can contact:

    $this->context 
    • I will specify: it turns out, the controller is used only for requests? - Dmitry Nevzorov
    • In general, as always in the MVC controller for managing data from the model and preparing data for the view - Artem Bondarenko
    • It goes without saying. But in the end, it is used only for the main content of the page and nowhere else? - Dmitry Nevzorov