David David - 7 months ago 114
PHP Question

How to build in 'maintenance mode' in Codeigniter?

I'm using latest codeigniter and I need to create a flag (ideally in the config) when turned to 'true', all pages display a 'maintenance mode' message instead of executing their controller code.

What is the best/simplest practice for doing this?

Answer

Extend the CI_Controller by putting a new file in your core directory called MY_Controller.

In this file's constructor, do something like this:

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

    if($this->config->item('maintenance_mode') == TRUE) {
        $this->load->view('maintenance_view');
        die();
    }
}

Let all controllers in your app inherit from that class.