【发布时间】:2013-07-20 12:13:51
【问题描述】:
有一种行为我不明白。
$test1 = $this->Post->find('all');
debug($test1);
它为该数组中的每个帖子提供预期的帖子数组,其中包含模型的所有字段:
id, field 1, field 2, field 3 ...
如果我使用以下语法:
$test2 = $this->paginate('Post');
debug($test2);
它仅显示预期的帖子数组,其中包含该数组中每个帖子的模型的某些特定字段:
id, field 2, field 5, field 14
为什么在使用paginate()-method 时会出现此输出?我如何为paginate()-method 获得与find()-method 相同的输出?
如果需要更多代码,请告诉我。
感谢任何帮助。
更新 1:
我发现我在这里加载的 DataTable-Component:https://github.com/cnizzdotcom/cakephp-datatable 可能会对这种奇怪的行为产生影响。但我还没有发现如何...
【问题讨论】:
-
请检查您是否在 $paginate 初始化期间使用了
fields选项。 -
不,就像: public $paginate = array( 'limit' => 5, 'maxLimit' => 25, 'order' => array( 'Post.DATE' => ' asc', ), );
-
在你的 PostsController 中试试这个......$options = array('fields' => array('Post.*')); $this->Post->递归 = 0; $this->分页 = $options; $posts = $this->paginate();调试($posts);
-
@ScrappyCocco:我将您的确切代码粘贴到我的控制器中,但它仍然只提供一些字段。我必须扩展我的问题,因为我发现它肯定与我安装的数据表助手有关,它使用 und 更改 paginate() 本身。
标签: database cakephp controller pagination datatables