Reputation: 5471
For some reason my model is not loading properly (i think), or at least I can not access its methods.
class Main extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('user');
}
public function index() {
$this->load->helper(array('form'));
$this->load->view('login');
}
public function login() {
if(isset($_POST['username'])) {
$username = $_POST['username'];
}
if(isset($_POST['password'])) {
$password = $_POST['password'];
}
// tried loading module here as well with no success
$data = array('username'=>$username, 'password'=>$password);
$this->model->validateUser($data);
}
}
Model
class User extends CI_Model {
public function __construct() {
parent::__construct();
}
public function validateUser($data) {
var_dump($data[0]." ".$data[1]);
}
}
This is what it returns me Call to a member function validateUser() on a non-object
I do not really see what and where is something wrong ? perhaps 2nd pair of eyes can help :) I am using CI 3+.
Upvotes: 0
Views: 717
Reputation: 4676
My advice for CI is to setup your Models with suffix (rename and the file)..
class User_model extends CI_Model
after that in your controller..
$this->load->model('user_model');
$this->user_model->dosomething();
Upvotes: 1