Codeigneter : How to call model method from controller class?
<p>I've recently started to learn OOP and Codeigniter. I've set up 2 new files in core; MY_Controller.php extending CI_Controller and MY_Model.php extending CI_Model. These files are both working, i'm able to call their methods in various controllers and models. However, I have a method in MY_Controller that checks if a user's logged in, if so it calls a method from MY_Model that updates the last active field in the user table. This method is working when I call it from say Login_model, but when I call it from MY_Controller it passes an error:</p>

<blockquote>
  <p>Call to undefined method Feed::update_last_active()</p>
</blockquote>

<p>Why is this? I'm trying to call a core model from my core controller, should I not be doing this? Below is my code.</p>

<p>MY_Controller.php:</p>

<pre><code>class MY_Controller extends CI_Controller{

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

    /**
    *   Check if the users sessions logged in
    */
    public function logged_in(){

        //Check the flag logged_in exists in the session
        if ($this-&gt;session-&gt;userdata('logged_in')){
            //Update the last active field in the user db
            $this-&gt;update_last_active($this-&gt;session-&gt;userdata('user_id'));
            return true;
        } else {
            return false;
        }

    }

}
</code></pre>

<p>MY_Model.php:</p>

<pre><code>class MY_Model extends CI_Model{

    /**
    *   Updates users last active 
    */
    public function update_last_active($id){

        $this-&gt;db-&gt;where('id', $id);
        $this-&gt;db-&gt;update('users', array('last_active' =&gt; date('Y-m-d H:i:s')));

    }

}
</code></pre>

<p>MY_Controller updated to @Tiger response (Returns <code>Call to undefined method CI_Loader::update_last_active()</code>):</p>

<pre><code>public function logged_in(){

        //Check the flag logged_in exists in the session
        if ($this-&gt;session-&gt;userdata('logged_in')){

            //Load my model
            $my_model = $this-&gt;load-&gt;model('MY_Model');

            //Update the last active field in the user db
            $my_model-&gt;update_last_active($this-&gt;session-&gt;userdata('user_id'));
            return true;
        } else {
            return false;
        }

    }
</code></pre>