Setup Maintenance Mode Using Hooks in Codeigniter

image1 (1)

There are so many ways to achieve maintenance mode in codeigniter. Codeigniter itself doesn`t provide such kind of functionality as other framework supports. This post supports how to setup maintenance mode using hooks.

Following are the steps to achieve this:

  1. Enable Hooks in the config.php file
  2. Create a custom config file for maintenance settings i.e maintenance_config.php
  3. Create an html called maintenance_view.php page under views or in root folder
  4. Create a Hook file called maintenance.php
  5. In the hooks config setup your hooks call to run on post_controller


<!DOCTYPE html>
    <style>Style your page</style>
    <p>We apologize but our site is currently undergoing maintenance at this time.</p>
    <p>Please check back later.</p>


<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['site_under_maintenance'] = TRUE;


if (!defined('BASEPATH')) exit('No direct script access allowed');
class Maintenance {
  var $CI;
  public function maintenance() {
     $this->CI = & get_instance();
     $this->CI->config->load('maintenance_config'); // Load custom config file
     if ($this->CI->config->item("site_under_maintenance")) {
        include(APPPATH . '/views/maintenance_view.php');


if (!defined('BASEPATH')) exit('No direct script access allowed');
$hook['post_controller'][] = array(
  'class' => 'maintenance',
  'function' => 'maintenance',
  'filename' => 'maintenance.php',
  'filepath' => 'hooks',
  'params' => array()