2

我正在获取我的所有用户并将它们显示在 CakePhp 的列表和分页中。但为什么它给我
错误:发生了内部错误。 并在堆栈跟踪下的行

$data = $this->Paginator->paginate('User'); 突出显示。

用户主页控制器.php

<?php

App::uses('AppController', 'Controller');

class UserhomeController extends AppController {

    public $components = array('Paginator', 'RequestHandler');
    public $helpers = array('Js', 'Paginator');
    public $paginate = array(
        'fields' => array('User.id', 'User.email'),
        'limit' => 25,
        'order' => array(
            'User.email' => 'asc'
        )
    );

    public function index() {
        $this->Paginator->settings = $this->paginate;

        // similar to findAll(), but fetches paged results
        $data = $this->Paginator->paginate('User');
        $this->set('user', $data);
    }

}

用户主页/index.ctp

 <?php
    $this->Paginator->options(array(
        'update' => '#content',
        'evalScripts' => true
    ));
    ?>
    <div class="container bottom_padding background_color_E8E3D7 height_full padding_top box_shadow">
        <table class="table table-striped background_color_eee">
            <!-- Here is where we loop through our $users array, printing out post info -->

            <?php foreach ($data as $user): ?>
                <tr>
                    <td><?php echo $user['User']['id']; ?></td>
                    <td>
                        <?php echo $this->Html->link($user['User']['title'], array('controller' => 'users', 'action' => 'view', $user['User']['id']));
                        ?>
                    </td>
                    <td><?php echo $user['User']['email']; ?></td>
                </tr>
            <?php endforeach; ?>
            <?php unset($user); ?>
        </table>
        <ul class="pagination">
            <?php
            echo $this->Paginator->prev(__('<<'), array('tag' => 'li'), null, array('tag' => 'li', 'class' => 'disabled', 'disabledTag' => 'a'));
            echo $this->Paginator->numbers(array('separator' => '', 'currentTag' => 'a', 'currentClass' => 'active', 'tag' => 'li', 'first' => 1));
            echo $this->Paginator->next(__('>>'), array('tag' => 'li', 'currentClass' => 'disabled'), null, array('tag' => 'li', 'class' => 'disabled', 'disabledTag' => 'a'));
            ?>
        </ul>
        <br/> 
        <?php
        echo $this->Paginator->counter(
                'Page {:page} of {:pages}, showing {:current} records out of
         {:count} total, starting on record {:start}, ending on {:end}'
        );
        ?>

    </div>
    <?php echo $this->Js->writeBuffer(); ?>
4

2 回答 2

10

添加public $uses = array('User');到您的控制器

于 2013-10-14T11:56:05.417 回答
-1
$data = $this->paginate('User');
于 2013-10-14T11:50:56.160 回答