Моя модель: как показано ниже, очень базовая
class User extends CI_Model
{
function __construct()
{
parent::__construct();
}
function getAll()
{
$this->db->order_by("lastName", "asc");
$this->db->order_by("firstName", "asc");
$this->db->order_by("userName", "asc");
$query = $this->db->get('user');
// test for result
if($query->num_rows() > 0)
{
return $query->result();
}
return NULL;
}
}
Мой контроллер: на самом деле часть моего контроллера, каждый раз при загрузке функции user / display по умолчанию, появляется ошибка (далее). Должна ли модель, загруженная в конструктор контроллера, быть доступной для всех других функций в том же контроллере?
class Users extends CI_Controller
{
function __contruct()
{
parent::__construct();
$this->load->model('user');
}
function display()
{
$data['users'] = $this->user->getAll();
$head['pageTitle'] = 'Users Panel';
$this->load->view('security/redirect');
$this->load->view('template/head', $head);
$this->load->view('user/usersPanel', $data);
$this->load->view('template/foot');
}
}
Моя ошибка: ссылка на строку "$ data ['users'] = $ this-> user-> getAll ()" в вышеприведенном контроллере
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Users::$user
Мое окружение:
Codeigniter 2.1.0;
Mac Lion;
MAMP 2.0;