У меня получилось вот так
<?php
namespace app\controllers;
use yii\web\Controller;
use yii\data\Pagination;
use app\models\Book;
use app\models\Author;
class SortController extends Controller {
public function actionSort() {
$years = Book::find()
->where('year>=1901')
->all();
$books = Book::find()->all();
$books = $books->select('author.name as author, COUNT(*) AS quantity')
->form('book')
->joinWith('author on book.id_author = author.id_author')
->groupBy('author.id_author');
var_dump($books);
return $this->render('sort', [
'years' => $years,
'books' => $books,
]);
}
}
Но выдаёт ошибку "all to a member function select() on array" вот в этой строчки
$books = $books->select('author.name as author, COUNT(*) AS quantity')