• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can a Controller extend another Controller?

[eluser]Fabian Graßl[/eluser]

I would like to use the same Constructor and some private functions in two different Controllers. Therefore I would like to create a Controller that is extended by two other Controllers. Is that possible?

Do a search on BaseController in the forums and you should get numerous hits.

[eluser]Michael Ekoka[/eluser]
You can create a set of base controllers for your application and store them in /application/libraries/MY_Controller.php.

class Users_Controller extends Controller{


class App_Controller extends Controller{


class Admin_Controller extends Controller{

Then you can just declare your other controllers in /application/controllers/ like
class Members extends Users_Controller{

If you need to extend one of your application's controllers instead, make sure to include the file at the top of the script like you would normally :
include APPPATH.'controllers/members.php';
class Gold extends Members{

[eluser]Derek Allard[/eluser]
This is one of the techniques I said I liked in my review of the book "Codeigniter for Rapid PHP Application Development". If you are just starting out, you might find it helpful, but I would recommend you first start with the userguide (not implying you haven't, more just good advice Wink)

[eluser]Fabian Graßl[/eluser]
Thank you very much! Smile

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.