Fatal error: calling a member function

I need help debugging my code. Im new in php and im currently using frameworkignign framework. Im trying to display the contents of my database table on 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 $query->result_array();

}

// get total number of users

function getNumUsers(){

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

}

}

?>

im with this error

Fatal error: call getUsersWhere () member function on a non-object in C: \ XAMPP \ HTDOCS \ printone \ Application \ Controllers \ users.php on line 16

What mistake?

+5
source share
1 answer

You incorrectly named your controller constructor, so it is not called, and your model does not load.

Edit

function __Users(){

to

function __construct(){
+4
source

All Articles