5
我需要幫助來調試我的代碼。林進入新的PHP和即時通訊使用codeigniter框架。我試着去我的數據庫表的內容顯示到我的網頁致命錯誤:致電成員函數
/controllers/users.php
$<?php
class Users extends CI_Controller{
function __Users(){
// load controller parent
parent::__Controller();
// load 'Users' model
$this->load->model('Users');
}
function index(){
$data['users']=$this->Users->getUsersWhere('userid <',5);
$data['numusers']=$this->Users->getNumUsers();
$data['title']='Displaying user data';
$data['header']='User List';
// load 'users_view' view
$this->load->view('users_view',$data);
}
}
?>
/models/users.php
$<?php
class Users extends CI_Model{
function __Users(){
// call the Model constructor
parent::__CI_Model();
// load database class and connect to MySQL
$this->load->database();
}
function getAllUsers(){
$query=$this->db->get('admin_user');
if($query->num_rows()>0){
// return result set as an associative array
return $query->result_array();
}
}
function getUsersWhere($field,$param){
$this->db->where($field,$param);
$query=$this->db->get('admin_user');
// return result set as an associative array
return $query->result_array();
}
// get total number of users
function getNumUsers(){
return $this->db->count_all('admin_user');
}
}
?>
有這個IM錯誤
Fatal error: Call to a member function getUsersWhere() on a non-object in C:\xampp\htdocs\printone\application\controllers\users.php on line 16
可能是什麼故障?
謝謝您的回覆...新的即時通訊到PHP以及與笨應該被替換調用構造函數的所有? 函數__Users()函數__construct() 以及模型? – nhoyti 2011-05-10 02:43:02
是的,你所有的構造函數應該被調用'__construct()'。有關更多信息,請參閱[PHP手冊](http://php.net/manual/en/language.oop5.decon.php)和[CI用戶指南](http://codeigniter.com/user_guide)。 – BoltClock 2011-05-10 02:47:26