开发者

Fatal error: Call to a member function

i need help in debugging my code. Im new into php and im currently using codeigniter framework. Im trying to display the content of my database table to my page

/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 $q开发者_如何学运维uery->result_array();

}

// get total number of users

function getNumUsers(){

return $this->db->count_all('admin_user');

}

}

?>

im having this error

Fatal error: Call to a member function getUsersWhere() on a non-object in C:\xampp\htdocs\printone\application\controllers\users.php on line 16

what could be the fault?


You misnamed your controller constructor, so it isn't being called and your model isn't being loaded.

Change

function __Users(){

to

function __construct(){
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜