使用PAGINATE据商务部http://book.cakephp.org/3.0/en/controllers/components/pagination.html,我想分页查询类似下面的结果:不能对查询结果
$unlocked_sitesQuery = $this->Deviceconnections
->find()
->contain([
'Agthemes.Sites',
'Agthemes.Agpois',
'Agthemes.Agthemelanguages'
])
->where(['request' => 'unlock'])
->groupBy('agtheme.site.id');
$unlocked_sites = $this->paginate($unlocked_sitesQuery);
,但我得到了以下错误:
Error: Call to undefined method ArrayIterator::alias()
File /home/mywebsite/vendor/cakephp/cakephp/src/Controller/Component/PaginatorComponent.php
Line: 154
这是什么意思?
编辑 看来,NDM是正确的,但医生说:
By default the paginate() method will use the default model for a controller. You can also pass the resulting query of a find method:
public function index(){$query = $this->Articles->find('popular')->where(['author_id' => 1]); $this->set('articles', $this->paginate($query));}
所以应该对结果集工作。或者我不明白文档解释的内容。可能。
看来你是对的,无论如何doc似乎说结果集被支持。看到我的编辑。 – 2ndGAB
@caBBAlainB Nope,文档说你可以传递查询。 “_resulting query_”不是“_result set_”,这是两个不同的东西,两个不同的类('\ Cake \ ORM \ Query','\ Cake \ ORM \ ResultSet'),前者是一个正在返回的查询结果,后者是执行查询时返回的结果(这就是你正在做的)。 ** http://book.cakephp.org/3.0/en/orm/retrieving-data-and-resultsets.html#working-with-result-sets**,** http://book.cakephp.org/ 3.0/en/orm/query-builder.html#queries-are-collection-objects ** – ndm
好的,好吧,我明白了。谢谢。 – 2ndGAB