退出CodeIgniter中自定义控制器类的执行以停止呈现视图

I created a class MyController and put in in core folder. It extends CI_Controller;

Then I created a controller Foo that extends myController. I wanted to do something like exit() in a certain point of the Foo's __construct function.

class Foo extends MyController{
    private $formats = array('json');

    function __construct(){
        parent::__construct();
        //do something
        exit();
    }
}

What I want with this is to stop rendering views in certain cases. But it's not working, if I go to myproject/foo/whatever it still goes to whatever action and renders the 404 default view

How can I achieve this?

The problem is your Controller name. You need to follow Codeigniter's naming convention.

Change the name of the class in the Core folder to start with MY_ such as MY_main_controller, rename your classes, and it should work.

Extending Core Classes