Answer the question
In order to leave comments, you need to log in
How to conditionally display elements in a standard CRUD module in YII2?
I created a table, filled it with data, made a model, then made CRUD through Gii, displays all the data.
The question is, is it possible to make a Where condition to display only those fields and how to do it, where user_id = Yii::$app->user->identity->getId()
Answer the question
In order to leave comments, you need to log in
Good afternoon.
Create a method in the controller
public function findModel()
{
if(!$model = Users::findOne(Yii::$app->user->identity->getId())){
return false;
}
return $model;
}
public function actionIndex()
{
return $this->render('index', ['model' => $this->findModel()]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question