I want to create two parent controllers: one for admin and one for user site. They have to extend a regular Controller class but each of them has to do different things.
A:
You can make a MY_AdminController
and a MY_UserController
in system/application/libaries
and use those to extend the rest of your controllers.
E.g.:
class Register extends MY_UserController
{
// Implementation
}
And:
class ManageUsers extends MY_AdminController
{
// Implementation
}
captaintokyo
2010-10-12 09:21:55
Thank you captaintokyo for suggestion but this does not work it says My_UserController and MY_AdminController not found...
Tamik Soziev
2010-10-12 09:34:36
put your My_UserCrontroller and My_AdminController into /system/application/libraries
ITroubs
2010-10-12 10:17:48
Where did you put `MY_AdminController` and a `MY_UserController`? I tried what I described above and it works fine.
captaintokyo
2010-10-12 10:52:25
+2
A:
I wrote up an article showing how you do this.
http://philsturgeon.co.uk/news/2010/02/CodeIgniter-Base-Classes-Keeping-it-DRY
You need to create an __autoload() function in your config.php or directly include the base controller above the class definition.
Phil Sturgeon
2010-10-12 10:27:15