如何限制ActiveDataProvider的查询?

时间:2015-12-15 08:57:39

标签: mysql yii2 cactivedataprovider

我正在尝试查询以获取第一个 10条记录,并将其传递给ActiveDataProvider

查询工作正常并且仅返回所需数量的记录,而ActiveDataProvider正在打印所有记录,这是我的代码:

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

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

1 个答案:

答案 0 :(得分:5)

Pagination设为false

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

Reference