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

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

Just a simple maintenance mode query string.

MY_Controller.php


PHP Code:
<?php


class MY_Controller extends CI_Controller {
    
    public function 
__construct() {
        
parent::__construct();
        
$this->maintenance_mode();
    }

    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 
                on.

            */

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

        }
    }

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



Then on any controller use extends MY_Controller


PHP Code:
<?php

class Maintenance extends MY_Controller {

    public function 
index() {
 
           $this->load->view('maintenance_mode');
    }


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!
Reply
#2

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB