How to build in 'maintenance mode' in Codeigniter?

前端 未结 6 1470
醉酒成梦
醉酒成梦 2020-12-15 00:20

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:43

    Here is what I've come up with for creating a maintenance mode.

    1. Enable Hooks in the config.php file
    2. Create an error_maintenance.php page under errors folder
    3. Create a Hook called maintenance
    4. In the hooks config setup your hooks call to run on post_controller

    application/errors/error_maintenance.php

    
    
      
        Maintenance
        
      
      
        

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

    Please check back later.

    application/hooks/maintenance.php

    CI =& get_instance();
          $this->CI->load->config("config_maintenance");    
          if(config_item("maintenance"))
          {
              $_error =& load_class('Exceptions', 'core');
              echo $_error->show_error("", "", 'error_maintenance', 200);
              exit;
          }
       }
    }
    

    application/config/hooks.php

    $hook['post_controller'][] = array(
       'class' => 'maintenance',
       'function' => 'maintenance',
       'filename' => 'maintenance.php',
       'filepath' => 'hooks',
       'params' => array()
    );
    

提交回复
热议问题