dongqianzhan8325 2013-10-14 11:37
浏览 70
已采纳

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

I am fetching all my users and show them in list and pagination in CakePhp. But why it is giving me
Error: An Internal Error Has Occurred. and under the Stack Trace the line

$data = $this->Paginator->paginate('User'); is highlighted.

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条回答 默认 最新

  • dongyao4419 2013-10-14 11:56
    关注

    Add public $uses = array('User'); to your controller

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染