Welcome Guest, Not a member yet? Register   Sign In
Maintenance Mode MY_Controller with QUERY_STRING

(This post was last modified: 02-04-2016, 12:13 PM by wolfgang1983.)

Just a simple maintenance mode query string.


PHP Code:

class MY_Controller extends CI_Controller {
    public function 
__construct() {

    public function 
maintenance_mode() {
$route base_url() . 'index.php?d=' $this->input->get('d') . '&c=' $this->input->get('c');

        if (isset(
$route)) {

$ignore = array(
base_url() . 'index.php?d=common&c=maintenance'

                 This checks if is on maintenance mode if so redirects to maintenance page.
                If you are logged on as admin you can still view the website even though maintenance mode 


            // It needs the in array check so will not throw redirect error.
if (!in_array($route$ignore) && config_item('maintenance') && !$this->isLogged()) {


// Testing this could be from a user library or something
public function isLogged() {

Then on any controller use extends MY_Controller

PHP Code:

class Maintenance extends MY_Controller {

    public function 
index() {

With the config_item('maintenance') on a config file $config['maintenance'] = FALSE; or TRUE what ever you need. FALSE for off TRUE for on
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!

Thanks for sharing, you could make a small improvement and put in an extra check in your maintenance controller that the maintenance page is only visible when the maintenance is on, if not redirect the users back to the home page.

That way users can press the refresh button and get redirected to the home page when the maintenance is over. Otherwise they keep staring at a maintenance message and keep refreshing forever.

Theme © iAndrew 2016 - Forum software by © MyBB