![]() |
Using model - issue while using methods - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Using model - issue while using methods (/showthread.php?tid=14221) |
Using model - issue while using methods - El Forum - 12-23-2008 [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> Using model - issue while using methods - El Forum - 12-23-2008 [eluser]GSV Sleeper Service[/eluser] looks like it's conflicting with the CI logging class, take a look at systems/codeigniter/Common.php Code: /** Using model - issue while using methods - El Forum - 12-23-2008 [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. Using model - issue while using methods - El Forum - 12-23-2008 [eluser]Spir[/eluser] Can I load a model in a model? Maybe not? maybe that the reason I have that issue... Using model - issue while using methods - El Forum - 12-23-2008 [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? Using model - issue while using methods - El Forum - 12-23-2008 [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 { Using model - issue while using methods - El Forum - 12-23-2008 [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. Using model - issue while using methods - El Forum - 12-23-2008 [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 { |