cakephp分页说错误:发生了内部错误

时间:2013-10-14 11:37:08

标签: php cakephp pagination

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

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

UserhomeController.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);
    }

}

USERHOME / 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(); ?>

2 个答案:

答案 0 :(得分:10)

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

答案 1 :(得分:-1)

$data = $this->paginate('User');