Extending Models |
[eluser]Unknown[/eluser]
Hello there! This is the scenario I have now: - My_model extends Model (My_model is at application/library). - My models (under application/models/) extends My_Model. And this is what I need/want to have: - My_model still extending Model - My_advanced_model extending My_model (My guess it that it should be at application/library) - My models extending My_advanced_model I already tried this scenario but didn't work; I got this error: "Fatal error: Class 'My_advanced_model' not found in ... application/models/my_modelname_model.php on line ..." Actually, if I call include the PHP file id does not fail. I'm using PHP/5.3.2 + Apache/2.2.15 Any suggestion?
[eluser]WanWizard[/eluser]
CodeIgniter doesn't support autoloading. The fact that the MY_ prefix works is because it is specifically coded that way. Either setup autoloading yourself, or have your MY_model manually include MY_advanced_model. You might want to read Phil Sturgeon's article on Base classses. It talks about Controllers, but it applies to Models as well...
[eluser]jedd[/eluser]
Hi mabrizio and welcome to the CI forums. [quote author="mabrizio" date="1290312695"] And this is what I need/want to have: - My_model still extending Model - My_advanced_model extending My_model (My guess it that it should be at application/library) - My models extending My_advanced_model [/quote] If your list of requirements does not include 'My models extending MY_Model' - then why not just put all the functionality your models require into MY_Model and be done with it? If you require some of your models to extend MY_Model and others to extend MY_advanced_model ... then as WanWizard says you can look at autoloading, or you can cheat by putting that second class in the MY_Model.php file. Might I suggest you try to avoid this kind of thing, though - keep the MY_* functionality at a minimum (it's expensive because it gets loaded on every controller or model load), move the functionality to helpers and libraries (a bit easier to manage when you'll load them).
[eluser]Unknown[/eluser]
Thank you guys! The information you guys posted was so useful, I found out the way to solve it thanks to your advice. Cheers, -M |
Welcome Guest, Not a member yet? Register Sign In |