There is an admin module. GRUD generated views, models, controllers Caregory model and Content model. Categories and subcategories of products are recorded in the Caregory and category table -

enter image description here Content has tile output enter image description here

Interconnected tables related to Content.category_id = Category.id I need to go to a link when clicking on a link in order to display a view with goods of a given category. As far as I understand it is necessary to make so that there was a request where categories are compared, something as like

$categories = Category::find() ->select('id','name') ->where('content.category_id = category.id') ->all(); 

But I do not know how to register. Created an action in the controller, where the url should be displayed

 public function actionAlbum() { return $this->render('album'); } 

So the question is how to display in the album view the data on the category parameters ??

1 answer 1

To pass parameters to the view, do this:

 public function actionAlbum() { $categories = Category::find() ->select('id','name') ->where('content.category_id = category.id') ->all(); return $this->render('album', [ 'categories' => $categories ]); } 
  • Thanks, and how to display with the view? - Vlad
  • one
    @Vlad To access a variable in view, simply call it, for example: <? = $ Categories; ?> - NPreston