CodeIgniter Forums

Full Version: Extending my own Controllers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Everyone, apologies if this has been asked before.

I'd like to know if its possible to extend my own controllers. I've been working on a web based applications for a while and I'm now starting to find each customer wishing to use the application has different requirements of how it should work. My thoughts are that if I generate a base structure and then extend the controllers to override any of the functions in which they require it work differently. First of all could you tell me if I'm on the correct track and secondly how do I go about extending my own controllers (if I can). I've tried the usual

PHP Code:
Class Reports2 extends Reports { } 

this doesn't work but I'm guessing it has something to do with the location of the file I'm trying to extend. My file structure is as follows:

PHP Code:
Application
--->controllers
-------->control_panel
------------>reports.php 

Any help is greatly appreciated.

Regards
Yes it is possible, but you should carefully read the documentation on how to do this.
The reference for CI 3.0 is here:

http://www.codeigniter.com/userguide3/ge...asses.html

Generally, your controller can extend a "Base Controller"
and there are some specific rules on naming that controller.

Other classes may also be extended and I advise studying the docs first...
Hi Thanks,

for the reply, I've not had a problem extending the core controllers, I've previously extended the main CI_Controller and I've also extended the Input and router classes. My problem is with extending my own classes within the controller folder. I've had a mess around with it but can't get it going hence asking the question. It doesn't appear to be as easy as extending the core classes therefore any point in the right direction would be welcome.
For anyone that comes across this post I managed to do it.

I used the usual

PHP Code:
class Test2 extends Test { } 

it was initially giving me an error that it couldn't find the file to extend but all I had to to do was use a simple include as shown below.

PHP Code:
require_once(APPPATH 'controllers/control_panel/test.php'