Welcome Guest, Not a member yet? Register   Sign In
Can a Controller extend another Controller?
#1

[eluser]Fabian Graßl[/eluser]
Hi!

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?
#2

[eluser]esra[/eluser]
Do a search on BaseController in the forums and you should get numerous hits.
#3

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

Code:
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
Code:
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 :
Code:
include APPPATH.'controllers/members.php';
class Gold extends Members{
}
#4

[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)
#5

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




Theme © iAndrew 2016 - Forum software by © MyBB