0

Possible Duplicate:
Fully Object Oriented framework in PHP

I am frustrated with CodeIgniter about one thing, you can't extend neither controllers nor models. I know you can do HMVC with a mod, and that somewhat gives you the inheritance abilities, but I'm not satisfied with that. Is there a PHP MVC framework that is object oriented and basically allows to extend the controllers, models?

Community
  • 1
  • 1
user1549397
  • 641
  • 2
  • 8
  • 15
  • 3
    I haven't used it so I can't say for sure, but I believe Fuel (http://fuelphp.com) was made to improve on that very aspect of CI. – Ayush Aug 25 '12 at 01:44

1 Answers1

5

The documentation for CodeIgniter says otherwise - one of first examples is:

If all you need to do is add some functionality to an existing library - perhaps add a function or two - then it's overkill to replace the entire library with your version. In this case it's better to simply extend the class. Extending a class is nearly identical to replacing a class with a couple exceptions:

The class declaration must extend the parent class. Your new class name and filename must be prefixed with MY_ (this item is configurable. See below.).

class MY_Controller extends CI_Controller {

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

// Then you can use it like this:
class Welcome extends MY_Controller {

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

    function index()
    {
        $this->load->view('welcome_message');
    }
}
Community
  • 1
  • 1
Sean Vieira
  • 155,703
  • 32
  • 311
  • 293
  • wow very nice...ok then I can just place the extended class in the same application/controllers folder? – user1549397 Aug 25 '12 at 02:05
  • 1
    @user1549397 - you can put them in `application/core` if you are using the 2.x version of CodeIgniter (see the docs I linked to in my answer). – Sean Vieira Aug 25 '12 at 02:45
  • there anyway to do this w/o altering the codeigniter core? – user1549397 Aug 25 '12 at 04:11
  • @user1549397 You'll be adding a file to the `core` folder not altering any existing files if you follow the method outlined above. – Sean Vieira Aug 25 '12 at 04:16
  • but in terms of application logic, extending the behavior( in this case the core controller class) is like extending the codeigniter framework right? Because what i want to be able to do is extend the behavior at the application level. – user1549397 Aug 25 '12 at 04:28
  • @user1549397 - Correct - in your application code you simply extend `My_Controller` rather than `CI_Controller`. – Sean Vieira Aug 25 '12 at 04:31
  • so i can place the controller that is extending another controller that is in the application/controllers in the same folder? – user1549397 Aug 25 '12 at 04:36
  • @user1549397 `application/core` not `system/...` that's the difference... – celwell Apr 14 '14 at 19:36