Cakephp Cake PHP 3需要find all方法的limit选项
在单元格内,我需要访问TreeOptions模型。 所以我写了这个:Cakephp Cake PHP 3需要find all方法的limit选项,cakephp,orm,find,clause,Cakephp,Orm,Find,Clause,在单元格内,我需要访问TreeOptions模型。 所以我写了这个: $this->loadModel( 'TreeOptions' ); $i = $this->TreeOptions->find( 'all' ); 但当我这样做的时候: foreach( $i as $row ) debug( $row->description ); 它只返回结果的最后一条记录。 我发现要使其按预期工作,唯一的方法是添加限制条款:
$this->loadModel( 'TreeOptions' );
$i = $this->TreeOptions->find( 'all' );
但当我这样做的时候:
foreach( $i as $row )
debug( $row->description );
它只返回结果的最后一条记录。
我发现要使其按预期工作,唯一的方法是添加限制条款:
$i = $this->TreeOptions->find( 'all', [ 'limit' => 200 ] );
然后,我就可以拿到整套唱片了。
我错过了什么
谢谢。
注意。在您的第一个代码段中,变量
$i
是查询尚未运行的状态。见以下摘录:
// Find all the articles.
// At this point the query has not run.
$query = $articles->find('all');
// Iteration will execute the query.
foreach ($query as $row) {
}
// Calling all() will execute the query
// and return the result set.
$results = $query->all();
// Once we have a result set we can get all the rows
$data = $results->toArray();
// Converting the query to an array will execute it.
$results = $query->toArray();