Cake PHP 3 需要限制选项才能找到所有方法
Cake PHP 3 needs limit option for find all method
在单元格内,我需要访问 TreeOptions 模型。
所以我写了这个:
$this->loadModel( 'TreeOptions' );
$i = $this->TreeOptions->find( 'all' );
但是当我像这样执行 foreach 时:
foreach( $i as $row )
debug( $row->description );
它只是returns结果的最后一条记录。
我发现让它按需要工作的唯一方法是添加 limit 子句:
$i = $this->TreeOptions->find( 'all', [ 'limit' => 200 ] );
然后,我可以获得整套记录。
我错过了什么?
谢谢。
问候。
在您的第一个代码段中,变量 $i
是查询尚未 运行 的状态。请参阅 CakePHP 3 Cookbook: Retrieving Data & Results — Using Finders to Load Data 的摘录:
// 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();
在单元格内,我需要访问 TreeOptions 模型。 所以我写了这个:
$this->loadModel( 'TreeOptions' );
$i = $this->TreeOptions->find( 'all' );
但是当我像这样执行 foreach 时:
foreach( $i as $row )
debug( $row->description );
它只是returns结果的最后一条记录。 我发现让它按需要工作的唯一方法是添加 limit 子句:
$i = $this->TreeOptions->find( 'all', [ 'limit' => 200 ] );
然后,我可以获得整套记录。 我错过了什么?
谢谢。 问候。
在您的第一个代码段中,变量 $i
是查询尚未 运行 的状态。请参阅 CakePHP 3 Cookbook: Retrieving Data & Results — Using Finders to Load Data 的摘录:
// 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();