Welcome Guest, Not a member yet? Register   Sign In
Using models within models
#1

[eluser]vendiddy[/eluser]
Is it possible to load a model within a model? The following code (which is a method from a model) does not work. When I call $this->user_model, it is not defined. However, if I put 'user_model' and 'task_model' in the $autoload['model'] array then I can access the models without a problem. Am I doing something wrong?

Code:
function create_new()
    {
        
        //Make sure user is logged in
        $this->load->model('user_model');
        $user_id = $this->user_model->get_logged_in_user_id();
        if ($user_id === FALSE) {
            //User is not logged in
            return FALSE;
        }
        
        $this->load->model('task_model');
        $task = $this->task_model->create_new();
        $data = array(
            'title' => 'Title',
            'description' => 'A description.',
            'task_id' => $task->id,
            'creator' => $user_id,
        );
        $this->db->insert('projects', $data);
        $id = $this->db->insert_id();
        
        return $this->_get_project($id);    
    }

Thanks!


Messages In This Thread
Using models within models - by El Forum - 07-13-2008, 04:43 PM
Using models within models - by El Forum - 07-14-2008, 01:17 AM
Using models within models - by El Forum - 07-14-2008, 02:05 AM
Using models within models - by El Forum - 07-14-2008, 03:39 AM
Using models within models - by El Forum - 07-14-2008, 03:59 AM
Using models within models - by El Forum - 07-14-2008, 08:20 AM
Using models within models - by El Forum - 07-14-2008, 11:57 AM
Using models within models - by El Forum - 07-14-2008, 12:09 PM
Using models within models - by El Forum - 07-14-2008, 09:58 PM
Using models within models - by El Forum - 07-14-2008, 11:42 PM



Theme © iAndrew 2016 - Forum software by © MyBB