1

This is the code that I'm running:

class Auth {
//put your code here

var $ci;

function __construct()
{
    $this->ci =& get_instance();
    $this->ci->load->library('session');
}

function Login($param)
{    
    // Get user from database           
    $this->ci->load->model('User_model');
    $user = $this->ci->user_model->getuserbyemail($param["email"]);

(or at least the part that I'm running)

I'm getting the following error:

Fatal error: Call to a member function getuserbyemail() on a non-object in C:\Users\Piers\Documents\Projects\dithinsi\application\libraries\Auth.php on line 28

Line 28 is the the bottom line of the code above.

Is it because I'm not handling the $ci variable properly?

tereško
  • 58,060
  • 25
  • 98
  • 150
Piers Karsenbarg
  • 3,105
  • 5
  • 31
  • 67
  • Doesnt `$this->ci` return the User_Model instance as opposed to storing it internally? Try `$users = $this->ci->load->model('User_model'); $users->getuserbyemail();` – prodigitalson Feb 06 '11 at 16:49
  • Did you copy the User_model file from another file and forget to rename the class? – Knossos Feb 06 '11 at 16:49

1 Answers1

2

It's because the user_model property is undeclared.

According to Codeigniter manual, the property name of a model object equals to the value of the argument given to model() method.

In PHP variable names are case sensitive. User_model does not equal to user_model.

Try what happens with:

$user = $this->ci->User_model->getuserbyemail($param["email"]);
Saul
  • 17,973
  • 8
  • 64
  • 88