A strutural issue

I’m developing a project and in the layout I will have a list of the recommended products. Usually in every page I get the data inside the controller than pass it to the view.

But in this case this "recommended section" will be common to all website where should I create the model necessary to render the recommended section?

Should I do it directly inside the layout template (views)?

Where should I create the model for recommended section since it will be use always and is independet of the any other action

Hi!

When I understand you request correct…

Sound like a job for a custom widget:

http://www.yiiframework.com/doc-2.0/guide-structure-widgets.html

Regards

Yes u have to keep in layouts/main.php

-> model of recommend should be in common/models.

-> nd controller in frontend/controllers just not give ny access permission.

For now I create a widget and inside the widget I create a dataprovider and use a listview to display the results. With this widget I have all the data access inside it, in my view I have something like this:


 <?= Recommendations::widget() ?> 

rups g I know that I should have a model in common/models and a controller in frontend/controllers, but imagine I call /site/contact this request will be managed by SiteController and by the actionContact, this action will render the contact view, but in my template I have a sidebar with the recommended products my question is how to pass the recommended products model for the listview inside the layout, without need to pass in in every action on every controller.

Every page will need this recommended products model that will be use directly in a listview in my layout view.