MY_Controller and resources - 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: MY_Controller and resources (/showthread.php?tid=19639) |
MY_Controller and resources - El Forum - 06-13-2009 [eluser]theprodigy[/eluser] If I load a library or helper in the constructor of MY_Controller, is that library or helper usable by the controllers that extend MY_Controller? MY_Controller: Code: function MY_Controller() extended class: Code: function add() I'm asking because this function "add" is throwing an error on Code: $this->form_validation->set_rules('name', 'Name', 'trim|required'); is there a way for me to make the resource available to children controllers? Thanks MY_Controller and resources - El Forum - 06-13-2009 [eluser]n0xie[/eluser] Yes. In your construct of the extended class, specify it should load the parent construct. Code: class MY_Controller extends Controller{ Code: class Example extends MY_Controller{ MY_Controller and resources - El Forum - 06-13-2009 [eluser]theprodigy[/eluser] the constructor of the extended class calls the parent's construtor. Code: class Galleries extends MY_Controller { I thought that was mandatory which is why I didn't specify it. The constructor of MY_Controller calls the Controller() constructor and loads the resources, the constructor of the extended class calls the constructor of MY_Controller, but for some reason, the resources aren't being able to be used by the extender. Do I need to assign the resources to a class level variable, and use them that way? Code: $this->form_val = $this->load->library('form_validation'); Is that what I need to do in order to use them in the extender? MY_Controller and resources - El Forum - 06-13-2009 [eluser]n0xie[/eluser] [quote author="theprodigy" date="1244960146"] Code: $this->form_val = $this->load->library('form_validation'); Is that what I need to do in order to use them in the extender?[/quote] No it should just work the way you have it now. :-s But if you're going to use the library in every controller you might as well load it in your autoload config file. You might try if that works... MY_Controller and resources - El Forum - 06-13-2009 [eluser]theprodigy[/eluser] not sure if this makes a difference, but just in case it does, I am running CI with Matchbox. This shouldn't make a difference, but figured I should probably mention it since what I have should work and isn't. MY_Controller and resources - El Forum - 06-13-2009 [eluser]theprodigy[/eluser] OK, got an update. The module is loading "MY_Controller". The module contains "MY_Controller". The problem is the site itself that the module is on has it's own MY_Controller, and the site's MY_Controller was the one getting extended, not the module's. So, this seems to be a Matchbox issue, and not a CI issue. I will take this to them. Thanks for your help. |