guness
guness

Reputation: 6616

codeigniter model inside a model, and model inside controller

I have actually 3 questions, but similar to each other:

Upvotes: 0

Views: 297

Answers (1)

Luke Dennis
Luke Dennis

Reputation: 14550

One way is to get the global variable for the main CodeIgniter object, and then load the model from that object rather than $this:

class Permissions extends Model
{
    function MyPermissionsFunction()
    {
        $ci =& get_instance();
        $ci->load->model('users');

        $ci->users->MyUserFunction();
    }
}

You can also sidestep the issue by combining your models together into one larger model. The main reason to keep them separate is to only load the models that you need; if you nearly always use both together (as would make sense, for Users and Permissions), you may be better off taking this approach.

Upvotes: 4

Related Questions