php - Calling model from codeigniter library shows error -
hello have created library auth.php
in application/libraries
authenticate if current user logged in or not. controller :
$session_data = $this->session->userdata('logged_in'); $this->load->library('auth'); $auth = new auth; $user_id = $auth->authenticate($session_data);
and library :
class auth{ function authenticate($vars){ $ci =&get_instance(); $ci->load->model('adminmodels/login_model'); $username = $vars['username']; $password = $vars['password']; $user_id = $vars['user_id'];; $user_type = $vars['user_type']; $check_login = $this->login_model->login($username,$password); //line 14 if($check_login){ $user_id = $user_id; }else{ $user_id = 0; } return $user_id; } }
but showing error :
a php error encountered
severity: notice
message: undefined property: auth::$login_model
filename: libraries/auth.php
line number: 14
whats wrong doing ??
while correct generally, in ci should call library this, not new
keyword:
$this->load->library('auth'); $user_id = $this->auth->authenticate($session_data);
also, since assigned global ci object variable, can't use $this
refer it:
$check_login = $this->login_model->login($username,$password); //line 14
should be:
$check_login = $ci->login_model->login($username,$password); //line 14
(since loaded model there: $ci->load->model('adminmodels/login_model');
)
Comments
Post a Comment