Setup Maintenance Mode Using Hooks in Codeigniter 3

How to Setup Maintenance Mode in Codeigniter 3

Most of the application needs a maintenance mode to indicate the user,the application going through under maintenance.

Here is the tutorial to setup the maintenance mode in codeigniter application.

CodeIgniter’s Hooks give a feature to modify the core functionality without modifying the core codeIgniter files.

We can use this featuire to setup maintenance page or under construction page in CodeIgniter.

Follow the steps to site as offline mode or maintenance mode in codeIgniter.

Enable Hooks in codeIgniter

First step is enable hooks to make the maintenance mode in codeIgniter .

Goto the application/config/config.php file and set $config[‘enable_hooks’] to TRUE.

Maintenance Config

Goto the application/config/config.php file and define a new config variable for maintenance mode.
Insert the following code at the end of the config.php file.

Defining Maintenance Hook

Next we need to mention codeIgniter about the maintenance hook,

Goto the application/config/hooks.php file and add the below lines.

Maintenance Hook Class

Create a new hook file called maintenance_hook.php in the application/hooks/ folder.

Maintenance Page

Create new maintenance.php file in the application/views/ directory and you can create your html maintenance view file.

 

Enable/Disable maintenance mode in codeigniter

Now you can enable the maintenance mode in codeigniter by $config[‘maintenance_mode’] = TRUE;
To disable the maintenance mode in codeigniter by make it to $config[‘maintenance_mode’] = FALSE;