Sunday, April 8, 2018

Yii2 activedataprovider

ActiveDataProvider data based on yii\db\Query or yii\db\ActiveQuery.

It provides data by using DB queries using $query.

You can use ORDER BY, GROUP BY, LIMIT, OFFSET just like normal sql statements in ActiveDataProvider.

How to use active dataprovider in Yii2


use yii\data\ActiveDataProvider;

$userQuery = User::find()->where(['id' => 9]);

$provider = new ActiveDataProvider([
    'query' => $userQuery,
    'pagination' => [
        'pageSize' => 5,
    ],
    'sort' => [
        'defaultOrder' => [
            'updated_by' => SORT_DESC
        ]
    ],
]);

1 comment:

Recent Update

yii2 session handling

use yii\web\Session; $session = Yii::$app->session; // start session $session->open(); // close session $session->close(); ...

Most Search