Search code examples
mysqlyii2cactivedataprovider

how to limit query for ActiveDataProvider?


I am trying to make a query to get the first 10 records for example, and pass it to the ActiveDataProvider.

The query is working fine and returning the required number of records only, while the ActiveDataProvider is printing all the records, here is my code:

    $query = new \yii\db\Query;
    $query->select('*')
            ->from('customers')
            ->limit(10);
    $query->createCommand();

    $dataProvider = new ActiveDataProvider([
        'query' => $query,
    ]);

Solution

  • Set Pagination to false :

    $dataProvider = new ActiveDataProvider([
    'pagination' => false
    ]);
    

    Reference