Есть 3 таблицы (новости, категории, юзеры).
Контроллер новостей:
Код: Выделить всё
public function actionAjax()
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$allnews = News::find()
->select('`news`.*, `category`.`cat_name`, `user`.`username`')
->leftJoin('category', '`category`.`id` = `news`.`cat_id`')
->leftJoin('user', '`user`.`id` = `news`.`user_id`')
->with('user', 'category')
->all();
return [
'allnews' => $allnews,
];
}