How to build in 'maintenance mode' in Codeigniter?

前端 未结 6 1774
太阳男子
太阳男子 2020-12-14 23:59

I\'m using latest codeigniter and I need to create a flag (ideally in the config) when turned to \'true\', all pages display a \'maintenance mode\' message instead of execut

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-15 00:49

    this one works well,

    application/views/vw_maintenance.php

        
        
          
            Maintenance
            
          
          
            

    We apologize but our site is currently undergoing maintenance at this time.

    Please check back later.

    the exit() function is very importantn don forget to put it at the bottom, it will prevent all pages from being displayed.

    application/libraries/maintenance.php

    class Maintenance{
    
        private $CI;
    
        public function __construct() {
    
            $this->CI =& get_instance();
    
            // flag on and off
            $this->flag( $this->CI->uri->segment(1) );
    
            // get the flag status
            $check_maintenance = $this->CI->db->select('flag_mode')->where(array('setting_name' => 'maintenance'))->get('tbl_settings')->result();
    
            //display view if true
            if($check_maintenance[0]->flag_mode == '1')
                $this->CI->load->view('vw_maintenance');
    
    
        }
    
        private function flag($command){
    
    
            $this->CI->db->where('setting_name', 'evolving');
    
            switch($command){
    
                case "activate":                
                    $this->CI->db->update('tbl_settings', array('flag_mode' => 1) ); 
                break;
    
                case "deactivate":
                    $this->CI->db->update('tbl_settings', array('flag_mode' => 0) );
                    redirect(site_url('/'));
                break;
    
            }
        }
    
    }
    

    autoload the library so it will be check every page load.

    now you can activate and deactivate maintenance mode by typing or

提交回复
热议问题