Using CI_Version 2.2.1 Models not connected in controller. I'm getting an error like
Undefined property: Administrator::$administrator_model & Fatal error: Call to a member function admin_authentication() on a non-object ...
class Administrator extends CI_Controller {
public function _construct()
{
parent::__construct();
$this->load->model('administrator_model');
}
public function login_authentication()
{
$username=$this->input->post('username');
$password=$this->input->post('password');
$check_login = $this->administrator_model->admin_authentication($username,$password);
}
Models
class Administrator_model extends CI_Model {
function __construct()
{
parent::__construct();
}
public function admin_authentication($username,$password)
{
$this->db->select('*');
$this->db->from('user_credential');
$this->db->where('db_username',$username);
$this->db->where('db_password',$password);
$query = $this->db->get();
return $query->result_array();
}
}
Please help to solve this issue, Thanks in advance.
class Administrator_model extends CI_Model {
function __construct()
{
parent::__construct();
$this->db = $this->load->database('default', true);
}
You have to load the db library first. OR In
autoload.php :
$autoload[‘libraries’] = array(‘database’);
is your model file in models folder root? eg: application/models/administrator_model.php
or it is in a sub folder eg: application/models/admin/administrator_model.php
then you have to load like $this->load->model('admin/administrator_model')
and the file name should be Ucfirst in CI3.0 but i forgot if it is necessary for CI2.2. (if you are using windows the filename wont bother until you deploy it to a linux server :)