如何限制对 ActiveDataProvider 的查询?
how to limit query for ActiveDataProvider?
我正在尝试进行查询以获取前 10 条记录,并将其传递给 ActiveDataProvider
。
查询工作正常,只返回所需数量的记录,而 ActiveDataProvider
正在打印所有记录,这是我的代码:
$query = new \yii\db\Query;
$query->select('*')
->from('customers')
->limit(10);
$query->createCommand();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
将Pagination
设为false
:
$dataProvider = new ActiveDataProvider([
'pagination' => false
]);
我正在尝试进行查询以获取前 10 条记录,并将其传递给 ActiveDataProvider
。
查询工作正常,只返回所需数量的记录,而 ActiveDataProvider
正在打印所有记录,这是我的代码:
$query = new \yii\db\Query;
$query->select('*')
->from('customers')
->limit(10);
$query->createCommand();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
将Pagination
设为false
:
$dataProvider = new ActiveDataProvider([
'pagination' => false
]);