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();

1 comment:

  1. This post will be very useful to us....i like your blog and helpful to me...
    Hire Yii Developers in India

    ReplyDelete

Recent Update

yii2 session handling

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

Most Search