I
I
IMrnsv2017-04-15 22:25:42
Yii
IMrnsv, 2017-04-15 22:25:42

Yii2. CRUD. How to display a list given a parameter?

Good day!
Everything is generated using Gii.

public function actionIndex()
    {
        $searchModel = new UsersSearch();	
    $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  
    return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }

this code in the controller generates a list of records from the database
, how can I rewrite the code so that records with a value in the ID field less than 10 are displayed from the database?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2017-04-16
@IMrnsv

Goodnight.
Try this: This is one of the options. You can set this parameter in the search model when you form the $dataProvider.

M
Maxim Timofeev, 2017-04-16
@webinar

If the search for the GridView is not needed, then this:

public function actionIndex()
    {
    $query = User::find()->andWhere(['>', 'id', 10]);
    $dataProvider = new ActiveDataProvider([
        'query' => $query,
    ]);
    return $this->render('index', [
            'dataProvider' => $dataProvider,
        ]);
    }

If needed, then as slo_nik said

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question