There are sections with genres. Games can have several genres. It is necessary to bring to the page all the games, among which there is a genre of the current section. Links look like gameshop/platform?id=5 , id is passed to action

The method for accessing the staging table is:

 public function getGenre(){ return $this->hasMany(Genre::className(), ['genre_id' => 'fk_genre_id']) ->viaTable('game_genre', ['fk_game_id' => 'id']); } 

I can not understand what should be the request, something like:

 public function actionGenre($id){ $query = Games::find(); $games = Games::find()->where([$query->genre->genre_id => $id])->all(); return $this->render('genre', [ 'games' => $games ]); } 

Please tell me the correct request.

    1 answer 1

    You need to make a connection in the Genre model with the Games model. And then:

     public function actionGenre($id){ $genre = Genre::findOne($id); $games = $genre->games; return $this->render('genre', [ 'games' => $games ]); }