Welcome Guest, Not a member yet? Register   Sign In
Parsing argument to model give me error "Undefined property"
#1

[eluser]LexXx[/eluser]
Hello Word to all Smile
I just begin my project with codeigniter and problems just started.

I have library file and function login:
Code:
public function login()
{
  $this->CI->load->model('user');

   if($this->CI->user->login_check() == true) // if the user's credentials validated...
   {
    $email = $this->CI->input->post('email');
    $password = md5($this->CI->input->post('password'));
    $data['user_info'] = $this->CI->user->get_user_data($email, $password);
    print_r($data['user_info']);
    die();
   }
   else // incorrect username or password
   {
    $data['heading'] = "Wrong email adress or password combination";
    $data['message'] = "Ooouchhh you just enter wrong email adress or password combination<a >CLICK HERE</a> to try again.<br />";
   }
}

Controller is not finished:
Code:
public function login()
{
  $this->authentication_lib->login();

}

couse my problem is in model
Code:
public function login_check()
{
  $this->db->where('email', $this->input->post('email'));
  $this->db->where('password', md5($this->input->post('password')));
  $query = $this->db->get('users');
  
  if($query->num_rows == 1)
  {
   return true;
  }
  else
  {
   return false;
  }
}

public function get_user_data($email, $password)
{
  $this->db->where('email', $this->email);
  $this->db->where('password', $this->password);
  $query = $this->db->get('users');
  
  if($query->num_rows == 1)
  {
   foreach($query->result() as $row)
   {
    $data[] = $row;
   }
   return $data;
  }
}

i try to send 2 argument from lib
Code:
$email = $this->CI->input->post('email');
$password = md5($this->CI->input->post('password'));
$data['user_info'] = $this->CI->user->get_user_data($email, $password);

and i have in called model
Code:
public function get_user_data($email, $password)
{
   //code
}
always have error

Message: Undefined property: Authentication::$email

Filename: core/Model.php

Line Number: 51

Message: Undefined property: Authentication::$password

Filename: core/Model.php

Line Number: 51


Can anyone help me???
#2

[eluser]ojcarga[/eluser]
I assume that the first piece of code you posted is the controller, right?
Why are you loading the model this way?
Code:
$this->CI->load->model('user');
#3

[eluser]LexXx[/eluser]
Code:
$this->CI->load->model('user');

This is in my library file, couse i can't load model like
Code:
$this->load->model('user');

I just complicate this post too much, i just need to know how to call model function with arguments.
Like this:
controller function example
Code:
public function login()
{
  $this->load->model('user');
  $username = "someuser";
  $password = "123456";
  $this->user->check_user($username, $password);  
}

model function example
Code:
public function check_user($username, $password)
{
  $username_to_check = $this->username;
  $password_to_check = $this->password;
  // go to search in db we have 2 vars

}
#4

[eluser]ojcarga[/eluser]
ok, got it, but when you do that...

Code:
public function login()
{
  $this->load->model('user');
  $username = "someuser";
  $password = "123456";
  $this->user->check_user($username, $password);  
}

//HERE IN THE METHOD MODEL, TRY USE
//$username INSTEAD OF $this->username
//$password INSTEAD OF $this->password
public function check_user($username, $password)
{
  $username_to_check = $this->username;
  $password_to_check = $this->password;
  // go to search in db we have 2 vars

}

This should be the way, tell us what happen.
#5

[eluser]InsiteFX[/eluser]
Code:
public function get_user_data($email, $password)
{
  // you do not need $this-> the variables are bassed into the method!
  $this->db->where('email', $email);
  $this->db->where('password', $password);
  $query = $this->db->get('users');
  
  if($query->num_rows == 1)
  {
   foreach($query->result() as $row)
   {
    $data[] = $row;
   }
   return $data;
  }
}

public function check_user($username, $password)
{
  $username_to_check = $username;
  $password_to_check = $password;
  // go to search in db we have 2 vars

}
#6

[eluser]LexXx[/eluser]
[quote author="InsiteFX" date="1336213438"]
Code:
public function get_user_data($email, $password)
{
  // you do not need $this-> the variables are bassed into the method!
  $this->db->where('email', $email);
  $this->db->where('password', $password);
  $query = $this->db->get('users');
  
  if($query->num_rows == 1)
  {
   foreach($query->result() as $row)
   {
    $data[] = $row;
   }
   return $data;
  }
}

public function check_user($username, $password)
{
  $username_to_check = $username;
  $password_to_check = $password;
  // go to search in db we have 2 vars

}
[/quote]

Thats solved my problem ty so much.




Theme © iAndrew 2016 - Forum software by © MyBB