public function actionBook() {
$genres = Genre::find()->all();
$books = $genres[0]->book;//или books
return $this->render('book', [
'books' => $books,
]);
}
class Book extends ActiveRecord {
public function getGenre() {
return $this->hasOne(Genre::className(), ['id_genre' => 'id_genre']);
}
}
class Genre extends ActiveRecord {
public function getBooks() {
return $this->hasMany(Book::className(), ['id_genre' => 'id_genre']);
}
}
class BookController extends Controller {
public function actionBook() {
$genre = Genre::find....;//Выбираем жанр
$books= $genres->books;
return $this->render('book', [
'books' => $books,
]);
}
}
А в контроллере