1

Possible Duplicate:
Codeigniter extending extended MY_Controller

I have been fiddling with this problem for a while now, and am at the point of frustration. I am extending the controller class with MY_Controller.

Here are the details:

  • __construct() does not seem to be called.
  • The file is located in application/core as it should be
  • The file is named MY_Controller.php
  • I have MY_ set up as the prefix for extensions (I have other extensions which work fine)

Here is my code:

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

class MY_Controller extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        echo 'TESTING!!!'; // This should print, followed by an ob_start() error
    }

}

I should get a page back that says TESTING!!! followed by an ob_start() error, but instead the page renders normally.

I have tried splitting up the constructor class and just calling a private function within MY_Controller, but that doesn't work. I know the file is being called because if I purposefully create a php error within MY_Controller.php, the page will error out. It seems to me that the __construct() is just not running.

Community
  • 1
  • 1
VictorKilo
  • 1,839
  • 3
  • 24
  • 39
  • `MY_Controller` should not live in application/core – Madbreaks Jan 04 '13 at 20:13
  • Where should it live? I was under the impression that it should live there... – VictorKilo Jan 04 '13 at 20:14
  • @Madbreaks I'm fairly certain that it should remain in application/core. The file is being called, it's just the constructor function which is not running.... – VictorKilo Jan 04 '13 at 20:17
  • MY_Controller should be under application/controllers. What is the reason to keep it in application/core? Also what version of CI are you running? – Karan Ashar Jan 04 '13 at 20:17
  • 1
    @KaranAshar No. Controllers go there, not an extended core class. http://stackoverflow.com/questions/6703803/error-in-extending-codeigniter-controller – VictorKilo Jan 04 '13 at 20:18
  • 1
    @Madbreaks This is not a duplicate of that question. I have read that question and it is not similar. Given your comments, I'm not even sure that you've read my question fully. – VictorKilo Jan 04 '13 at 20:20

1 Answers1

5

Can you show an example of one your controllers under application/controllers? Pls note that the controllers under application/controller should extend MY_Controller instead of CI_Controller - I think this is what you missed.

For example, under your controller application/controller/test.php. it should look like this:

class Test extends MY_Controller {        
    public function index()
    {
         echo 'test';
    }
}
Ardy Dedase
  • 1,088
  • 9
  • 15