0

I'd like to know if it's possible to extend my own controllers. I've been working on web-based applications for a while and I'm now starting to find each customer that wishes 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 that the customers require to 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:

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:

Application
--->controllers
-------->control_panel
------------>reports.php
2
  • 1
    This is a great/quick article on extending controllers. It might help? philsturgeon.uk/blog/2010/02/… Commented Jan 12, 2015 at 21:11
  • @dragonslovetacos that is an excellent article. I was thinking of it while writing my answer Commented Jan 12, 2015 at 21:13

1 Answer 1

1

If I am not mistaken then you should be able to easily do this:

reports2.php

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once(APPPATH.'controllers/control_panel/reports.php');

Class Reports2 extends Reports {

    public function __construct(){
        parent::_construct();
    }

    public function index(){

    }

}
Sign up to request clarification or add additional context in comments.

2 Comments

Hi, thanks, I was trying to use PHP5's __autoload which just didn't want to work. The above will do fine. thanks
@user1530205 You're welcome. I've never looked into auto-loading controllers at this level but I've certainly done it when implementing separate base controllers in order to control two separate applications more efficiently.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.