Using model - issue while using methods |
[eluser]Spir[/eluser]
Hi I have a weird issue. I load a model then I use some methods from that model but it says the model is null... I tought it's because of the name of my model but after checking the reserved names it's look ok. Here is my code within a model that works fine : Code: $this->load->model('log'); Example : Code: class Log extends Model { Quote:Undefined property: My_other_model::$log</p>
[eluser]GSV Sleeper Service[/eluser]
looks like it's conflicting with the CI logging class, take a look at systems/codeigniter/Common.php Code: /**
[eluser]Spir[/eluser]
I also tried this but it the same results : Code: $this->load->model('log','mylog'); I also changed the name of the model to mylog for example and it doesn't work either... It's look like something is wrong in my code but it's a totally classic model.
[eluser]Spir[/eluser]
Can I load a model in a model? Maybe not? maybe that the reason I have that issue...
[eluser]Spir[/eluser]
it looks like it's not possible. http://ellislab.com/forums/viewthread/49625/ I have load my model in the controller but it sucks because I want to log some CRUD event of my models so it does not have to be manage in controller. Maybe I should set it has a helper? But I feel not because it's not an helper. I manage data in my Log model. I want my models to use the model "log" so they can log in the database some events. I guess I should just have my log model to be a model and the other model to inherit the Log model so I can use those method. Do you guys think that would be a good idea?
[eluser]Spir[/eluser]
So basically I would have : Code: class Log extends Model { And a model that is tracked by logs : Code: class My_model extends Log {
[eluser]Spir[/eluser]
finally I did this : in my model called My_model (previously). So remember this is the model that need to load my Log model : Code: class My_model extends Model { NB: I'm not using "Log" as a name for my model anymore. I guess I would have some conflict.
[eluser]Colin Williams[/eluser]
Right. The issue is that when you load the model in another model, you don't get an instance of that model available to your current model. That's why getting a reference to the CI object is necessary. For instance, this should work: Code: class A_model extends Model { |
Welcome Guest, Not a member yet? Register Sign In |