【发布时间】:2016-02-04 21:44:11
【问题描述】:
我一直在使用 CakePHP 3.0 的开发人员预览版,但我一直在尝试让新的 ORM 与分页一起工作。
在我的 PostsController.php 中有:
<?php
namespace App\Controller;
use App\Controller\AppController;
class PostsController extends AppController {
public $name = 'Posts';
public $uses = 'Posts';
public $components = ['Paginator'];
public $paginate = [
'fields' => ['Posts.id'],
'limit' => 1,
'order' => [
'Post.id' => 'asc'
]
];
public function index() {
$posts = $this->paginate('Posts');
$this->set('posts', $posts);
}
}
但是分页正在工作,但数据没有返回。显然这是因为数据不是直接在新的 ORM 中返回,而是一个对象......有没有人尝试过这个?知道如何解决问题以使其与分页器一起使用?
我一直在阅读迁移指南:http://book.cakephp.org/3.0/en/appendices/orm-migration.html,但没有看到任何关于将其与分页器结合使用的信息。
注意:我无法调试 $posts 并在此处显示它,因为它大约有 2000 行代码,其中包含有关 ORM 的各种内容。这是一个品尝者...
object(Cake\ORM\ResultSet) {
[protected] _query => object(Cake\ORM\Query) {
[protected] _table => object(Cake\ORM\Table) {
[protected] _table => 'posts'
[protected] _alias => 'Posts'
[protected] _connection => object(Cake\Database\Connection) {
[protected] _config => array(
'password' => '*****',
'login' => '*****',
'host' => '*****',
'database' => '*****',
'prefix' => '*****',
'persistent' => false,
'encoding' => 'utf8',
'name' => 'default',
'datasource' => object(Cake\Database\Driver\Mysql) {
[protected] _baseConfig => array(
'password' => '*****',
'login' => '*****',
'host' => '*****',
'database' => '*****',
'port' => '*****',
'persistent' => true,
'flags' => array(),
'encoding' => 'utf8',
'timezone' => null,
'init' => array(),
'dsn' => null
)
[protected] _config => array(
'password' => '*****',
'login' => '*****',
'host' => '*****',
'database' => '*****',
'port' => '*****',
'prefix' => '*****',
'persistent' => false,
'encoding' => 'utf8',
'name' => 'default',
'flags' => array(),
'timezone' => null,
'init' => array(),
'dsn' => null
)
[protected] _autoQuoting => false...
如您所见,它是一个巨大的对象,并且可能数据就在其中。
【问题讨论】:
-
debug($posts->toArray());的作用是什么?
标签: php cakephp pagination cakephp-3.0