致命错误:调用成员函数

nho*_*yti 5 php codeigniter

我需要帮助调试我的代码.我是新的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);
    }
}
?>
Run Code Online (Sandbox Code Playgroud)

/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');

}

}

?>
Run Code Online (Sandbox Code Playgroud)

我有这个错误

致命错误:在第16行的C:\ xampp\htdocs\printone\application\controllers\users.php中的非对象上调用成员函数getUsersWhere()

可能是什么错?

Bol*_*ock 4

您错误命名了控制器构造函数,因此它没有被调用,并且您的模型也没有被加载。

改变

function __Users(){
Run Code Online (Sandbox Code Playgroud)

function __construct(){
Run Code Online (Sandbox Code Playgroud)