【问题标题】:cackphp multiple pagination with same page Error: An Internal Error Has Occurredcackphp 多个分页与同一页面错误:发生内部错误
【发布时间】:2014-07-03 23:09:56
【问题描述】:

我的系统有不同角色的用户。我想在单独的表格中显示同一页面中的所有用户。所以我做了以下事情。

用户模型(User.php)

App::uses('AppModel', 'Model');

class User extends AppModel {

    public $useTable = 'users';

}

AUser 模型(Auser.php)

App::uses('User', 'Model');

class Auser extends User {

}

BUser 模型(Buser.php)

App::uses('User', 'Model');

class Buser extends User {

}

UsersController.php

App::uses('Auser', 'Model');
App::uses('Buser', 'Model');

class UsersController extends AppController {

    public function index() {
        $Auser = new Auser();
        $Buser = new Buser();

        $this->paginate = array(
            'Auser' => array(
                'conditions' => array('Auser.role' => 0),
                'limit' => 5
            ), 
            'Buser' => array(
                'conditions' => array('Buser.role' => 1),
                'limit' => 5
            ),           
        );

        $this->set('ausers', $this->paginate('Auser'));
        $this->set('busers', $this->paginate('Buser'));


 }
}

但它显示以下错误。

错误:发生内部错误。

有什么问题?

【问题讨论】:

  • $this->loadModel('Auser'); 而不是$Auser = new Auser();
  • 启用调试模式以获取真正的错误。
  • 另外,你不能分页两次..
  • 查看堆栈跟踪并找到您在哪一行得到错误。只需更改您的调试模式即可获得错误

标签: php cakephp pagination cakephp-2.4


【解决方案1】:

错误逗号和如何加载模型是如此

$this->loadModel('Auser');

所以:

class UsersController extends AppController {

    public function index() {
        $this->loadModel('Auser');
        $this->loadModel('Buser');
        $this->paginate = array(
            'Auser' => array(
                'conditions' => array('Auser.role' => 0),
                'limit' => 5
            ), 
            'Buser' => array(
                'conditions' => array('Buser.role' => 1),
                'limit' => 5
            )
        );

        $this->set('ausers', $this->paginate('Auser'));
        $this->set('busers', $this->paginate('Buser'));


 }
}

【讨论】:

    猜你喜欢
    • 2013-10-21
    • 2011-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-21
    • 1970-01-01
    • 1970-01-01
    • 2019-09-21
    相关资源
    最近更新 更多