Answer the question
In order to leave comments, you need to log in
How to display data from a linked table?
<?php
namespace api\modules\v1\controllers;
use api\filters\Auth;
use common\models\HistoryRating;
use common\models\user\Person;
use common\models\user\User;
use Yii;
use yii\data\ActiveDataProvider;
use yii\rest\Controller;
use yii\web\NotFoundHttpException;
use yii\db\ActiveQuery;
class UserController extends Controller
{
public function actionWall($login){
$user = Yii::$app->user;
$user = User::find()->where(['username' => $login])->with(['user', 'person'])->one();
if ($user) {
return $user;
}
throw new NotFoundHttpException(Yii::t('app', 'The requested user does not exist.'));
}
}
public function fields()
{
return ['id', 'email', 'username', 'rating'];
}
Answer the question
In order to leave comments, you need to log in
Try to get the necessary models with separate requests, and then mold them into a common array and return them.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question