我使用Yii框架的模型搜索功能进行搜索,但当我在没有任何过滤器的情况下使用它时,它不会返回完整的结果。有人能帮忙吗???
$model->search()->getData();是我用来获取结果的命令。
这是我的示例代码:-
$model=new modelName('search');
$results = $model->search()->getData();
在模型中,只有正常的搜索标准
感谢
$model->search()返回一个CActiveDataProvider对象。默认情况下,CActiveDataProvider查询是分页的。这很有用,因为CActiveRecords占用大量内存,并且在web应用程序中通常会出现分页结果。
您应该循环浏览CActiveDataProvider页面,或禁用CActiveData Provider上的分页。
解决方案1:使用CDataProviderIterator循环浏览所有CActiveDataProvider页面
这通常是最好的选择,因为CDataProviderIterator对所有结果进行迭代,从而使CActiveDataProvider保持较低的内存使用率。
$results = $model->search();
$iterator = new CDataProviderIterator($results );
foreach($iterator as $model) {
...
}
解决方案2:禁用分页(不推荐)
$results = $model->search();
$results->setPagination(false);
foreach($results->getData() as $model) {
...
}