I’m finding out about how CI scopes things a bit late. I’ve been creating models like this:
$this->load->model('user');
$this->user->load ($user_id);
Then I’d pass around the $this->user object to be able to access all the various things I needed from that object, update properties and such.
I downloaded a Phil Sturgeon CI app callend PyroCMS and I see that he mostly returns data from his object’s methods, much like a straight-up procedural function.
So, are models really only supposed to be used at namespaces in CI?
I’m finding that using them the way I am, with a just-now-discovered scope issue, I’m over-writing my models.
Of course the solution is the name it when loading, but that means I have to track and be wary of what name each one of them is using, which is going to be a problem.
Is this how others use the CI models, mainly returning things from them instead of using them as full featured objects?
I found Phil Sturgeon responded to this question: Codeigniter models are just utility classes? with essentially what I need to know. I can still use the loaded model by using the php
$object = new Classsyntax. I will do this:With the
privateand thenewI think I’m safe finally. Probably I should go ahead and do that outside of the model, and not in the constructor, then pass it in as a dependency. I had given up on DI.I think I’ve talked myself off the ledge.