CodeIgniter Forums
multiple MY_Controller? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: multiple MY_Controller? (/thread-28503.html)



multiple MY_Controller? - El Forum - 03-12-2010

[eluser]upstream[/eluser]
Hi Guys,

is it possible to have multiple MY_Controller? or rather multiple extention of MY_Controller? if so, how? Like for example. i need to extend the Controller for Admin Pages, and again, extend it for Members Pages.

If this is not possible, is there any better solution for this problem? thanks!!!


multiple MY_Controller? - El Forum - 03-12-2010

[eluser]tomcode[/eluser]
Yes and No, No, You can have only one file MY_Controller.php.

But, You can define several classes inside this file :

Code:
// For all common methods
class MY_Controller extends Controller{
    
}
// Some special Member stuff
class Member_controller extends MY_Controller{
    
}
// ..
class Admin_controller extends Member_controller{
    
}
// A completely different set of stuff
class Special_controller extends Controller{
    
}
// And instead of using helper files ...
function common_helper_function()
{
}



multiple MY_Controller? - El Forum - 03-13-2010

[eluser]upstream[/eluser]
i see, that's what i currently did. that is also applicable to other like form validations, correct? thank you tomcode!


multiple MY_Controller? - El Forum - 03-13-2010

[eluser]tomcode[/eluser]
Sure, but I usually work rather with models and librairies than with multiple base controllers, up to You, what You like best.