Answer the question
In order to leave comments, you need to log in
How to display posts of a specific user?
I'm trying to implement the output on the main page of the personal account of the list of user posts belonging to him.
in PostController I edit actionIndex
public function actionIndex()
{
//сохраняю в переменную ид пользователя. В бд в таблице есть ячейка author_id с которой планируется сравнивать данные из переменной.
$autorId = Yii::$app->user->identity->id;
$dataProvider = new ActiveDataProvider([
//Сравниваются данные из переменной для последующего вывода
'query' => Product::find()->where(['autor_id' => $autorId])->all(),
]);
return $this->render('index', [
'dataProvider' => $dataProvider,
]);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question