My system has users with different role. I want show all users in same page in separate tables. So i did following things.
User Model (User.php)
App::uses('AppModel', 'Model');
class User extends AppModel {
public $useTable = 'users';
}
AUser model (Auser.php)
App::uses('User', 'Model');
class Auser extends User {
}
BUser model (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'));
}
}
But it show following error.
Error: An Internal Error Has Occurred.
What is the issue?
error comma and how to load models is so
$this->loadModel('Auser');
so:
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'));
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.