0

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+.

2
  • 1
    Why do you try to use $this->model-> when you are loading 'user'? Commented Nov 26, 2015 at 15:26
  • @Svetlio oh god... yes :)... Commented Nov 26, 2015 at 15:28

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

1 Comment

correct answer and handy tip ;) will accept after cooldown. Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.