CodeIgniter Forums

Full Version: multiple MY_Controller?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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!!!

El Forum

[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()
{
}

El Forum

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

El Forum

[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.