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

[eluser]intractve[/eluser]
[quote author="XedinUnknown" date="1261150591"]

intractve,

What you have shown me is exactly what I am trying to do, and I can confirm that it kinda works. However, imagine a situation like this:
Code:
// Inside a controller
$this->load->model('customer', 'user');

// Inside the 'Customer' model
$this->load->model('user', 'user');

This code didn't work for me. As far as I could tell, the second one was either not beind loaded at all, or was overriding the first one, I am not sure. I could not know from inside the Customer model, what other models where loaded before. I think the cause of the problem is the absence of Namespaces and Singletons. Correct me if I'm wrong.[/quote]

You cannot access (as far as I know) two models using the same namespace, when you load the second model, it replaces the first's namespace 'user'.

The namespace user is available throughout the instance once its loaded, whether it be in the model , view or controller. You can access that namespace using this->user, but when u assign something else to this->user the first model is replaced.

for eg.
if u load model 'customer' , 'user' in your controller and following that u load a model called 'user','user1':
inside of the user1 model's functions you can access $this->user->function();
even without explicitly calling for load model in the user1 model. because the current instance already has the $this->user loaded by the controller.

Hope i am clear, I do not mean to teach or anything, just puttin it out here for the benefit of anyone else too.


Messages In This Thread
Using models from within models - by El Forum - 12-16-2009, 08:27 AM
Using models from within models - by El Forum - 12-16-2009, 08:31 AM
Using models from within models - by El Forum - 12-16-2009, 08:34 AM
Using models from within models - by El Forum - 12-16-2009, 09:07 AM
Using models from within models - by El Forum - 12-16-2009, 09:10 AM
Using models from within models - by El Forum - 12-16-2009, 09:17 AM
Using models from within models - by El Forum - 12-16-2009, 09:25 AM
Using models from within models - by El Forum - 12-16-2009, 09:46 AM
Using models from within models - by El Forum - 12-17-2009, 10:18 AM
Using models from within models - by El Forum - 12-18-2009, 03:36 AM
Using models from within models - by El Forum - 12-18-2009, 04:04 AM
Using models from within models - by El Forum - 12-18-2009, 05:23 AM
Using models from within models - by El Forum - 12-18-2009, 08:13 AM
Using models from within models - by El Forum - 12-18-2009, 08:18 AM
Using models from within models - by El Forum - 12-18-2009, 08:29 AM
Using models from within models - by El Forum - 12-18-2009, 08:36 AM
Using models from within models - by El Forum - 12-18-2009, 09:28 AM
Using models from within models - by El Forum - 12-18-2009, 10:20 AM
Using models from within models - by El Forum - 12-18-2009, 11:50 AM



Theme © iAndrew 2016 - Forum software by © MyBB