S
S
Sergey Suntsev2017-01-23 14:41:29
Yii
Sergey Suntsev, 2017-01-23 14:41:29

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

1 answer(s)
D
Dmitry, 2017-01-23
@GreyCrew

Good afternoon.
Create a method in the controller

public function findModel()
  {
    if(!$model = Users::findOne(Yii::$app->user->identity->getId())){
      return false;
    }

    return $model;
  }

You can display the required fields using this method.
public function actionIndex()
  {
    return $this->render('index', ['model' => $this->findModel()]);
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question