I’m going to share with you How to configure CodeIgniter maintenance mode. Maintenance mode allows you to show a user-friendly message to your visitors during website maintenance, rather than a broken site. Often you might need a longer period of time to work on your website.
The Hooks from CodeIgniter offer a feature to change the core functionality without changing the core files.
Enable Hooks
You need to make hooks first. Edit application/config/config.php
file, set $config['enable hooks']
to TRUE.
Define Maintenance Config
Goto application/config/config.php
file, and set a new maintenance mode config variable. Insert next code at the end of the config.php
file.
Defining Maintenance Hook
To let the system know about the maintenance hook, edit the application/config/hooks.php
file and register the maintenance hook.
In the above config array,
pre_system:
One of the hook points available in CodeIgniter. During execution of the program the hook will be called very early and it is the good point to display the maintenance tabclass:
The class name wishes to be invoked.function:
The method name wish to call.filename:
Filename withclass/function
filepath:
Directory name with hook file.
Maintenance Hook Class
Create a new application/hooks/maintenancehook.php
hook file, and add the following php code to write. The following code checks the maintenance variable $config['maintenance mode']=TRUE configuration value that we have deinfected in the application/hooks/config.php
file and if that value is true, it will load the site maintenance page from the application views directory.
Maintenance View Page
Create a new maintenance.php file in the application/views/
directory and you can create your html view file.