Bobby Bruce
Bobby Bruce

Reputation: 361

Codeigniter - call to undefined method

I have a project in Ci and I can't get it to recognize my check2() for some reason. CI keeps throwing Fatal error: Call to undefined method CI_Loader::check2()

controller (Login.php)

class Login extends CI_Controller {

 public function index() {
 // Page variables
 $page['title'] = "Analytics Login";  
 $this->load->view('header', $page); 
 $this->load->view('login');
 $this->load->view('footer');
 }

 public function verify() {

 $verifier = $this->load->model('Verifylogin_model');

 $username = $this->input->post('username');
 $password = $this->input->post('password');

 if((!$verifier->check2($username,$password))) {
 $this->load->view('login');
 } else {
 redirect('home', 'refresh'); 
 }
 }
}

Model (verifylogin_model.php)

<?php
Class Verifylogin_model extends CI_Model {

 function __construct() {
 parent::__construct();
    }

 public function check2($username, $password) {

 $this->db->select('user_id, user_email');
 $this->db->from('admin_users');
 $this->db->where('user_email', $username);
 $this->db->where('user_pass', md5($password));
 $this->db->limit(1);

 $results = $this->db->get();

 if ($results->num_rows() == 1) {
 return true;
 } else {
 return false;
 }
 }
}
?>

Upvotes: 0

Views: 3135

Answers (3)

Suyog
Suyog

Reputation: 2482

Access the model method in following manner

 $this->load->model('verifylogin_model');

 $this->verifylogin_model->check2();

Upvotes: 1

DNX
DNX

Reputation: 118

CI use "dependency injection" heavily. Loader is not a factory class which you can't get Verifylogin_model instance directly. In CI, you should call the model like the following example

if (!$this->Verifylogin_model->check2($username, $password)) {
 /* your code */
}

Upvotes: 1

Ron Dadon
Ron Dadon

Reputation: 2706

CI loader does'nt return the model instance, but the global CI instance.

You can use:

$this->load->model('Verifylogin_model');
$verifier = $this->Verifylogin;

Upvotes: 1

Related Questions