Welcome Guest, Not a member yet? Register   Sign In
model in a model
#1

[eluser]Bramme[/eluser]
Hey guys,

Just a quick question. It's been a while since I worked with CodeIgniter and I kinda forgot: can you use models within models? I was trying to access my users model in a content model (to get the content writer's name since only an ID is stored) but I get a "Call to undefined method mdl_content::get_user()" error.

What would be the best way to solve this problem? I've copied the get_user method from the users model for now, but that just seems silly.
#2

[eluser]dpgtfc[/eluser]
What about using a library as an intermediary?
#3

[eluser]Bramme[/eluser]
I guess I could, but it's all very specific database interaction... And I'd like to keep that in models. I see libraries as something I could use for a series of projects.
#4

[eluser]dpgtfc[/eluser]
[quote author="Bramme" date="1229986278"]I guess I could, but it's all very specific database interaction... And I'd like to keep that in models. I see libraries as something I could use for a series of projects.[/quote]

Personally I don't like my models calling other models. I'll use my controller to pass the data from one model to another, I just thought it was a good option if you had to.
#5

[eluser]Henry Weismann[/eluser]
I don't like to call other models from my models as well. The models should have no knowledge of other models. In my view, if you want to use an existing function in another model, the controller should load the other model and use it.




Theme © iAndrew 2016 - Forum software by © MyBB