Showing posts with label yii2 arraydataprovider gridview. Show all posts
Showing posts with label yii2 arraydataprovider gridview. Show all posts

Sunday, April 8, 2018

Yii2 arraydataprovider

ArrayDataProvider just name represent based on data array. It is uses $allModels property which occupied all the data and it can be sorted.

You can set $sort and $pagination methods for sorting and pagination behaviors.

How to use Arraydataprovider in Yii2

$query = new Query;
$arrayDataProvider = new ArrayDataProvider([
    'allModels' => $query->from('user')->where(['status'=>true])->all(),
    'sort' => [
        'attributes' => ['name', 'id'],
    ],
    'pagination' => [
        'pageSize' => 5,
    ],
]);
// get the user query result
$user = $arrayDataProvider->getModels();

Recent Update

yii2 session handling

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

Most Search