title: CakePHP - Create an Offline/Online feature for a site
body: <p>======================================== <strong>EDIT</strong> ====================================</p>
  
  <p>Per charles suggestion, I accomplished the Offline/Online feature using the following code, based on Charles code:</p>
  
  <pre><code>&lt;?php
  
        Class AppController extends Controller{
  
            // prevents unauthorized access
            public $components = array('Auth');
  
            // the name of the model storing site_offline boolean
            public $uses = array('Configuration');
  
            // callback invoked before every controller action
            public function beforeFilter() {
  
                // returns your site_offline status assuming 0 is offline
                if ($this-&gt;Configuration-&gt;get_site_status() == 1) {
                     $this-&gt;Auth-&gt;allow('*');
                }else {
                     if(($this-&gt;Configuration-&gt;get_site_status() == 0) and (!$this-&gt;Auth-&gt;user() == null)){
                         // I set it up like this for now to allow access to any authenticated user, 
                         //but later will change it to only allow admins access thru a login form
                         $this-&gt;Auth-&gt;allow('*');
                     }else{ 
                         //If site is offline and user is not authenticated, sent them to 
                         // the a screen using the OFFLINE layout and provide a screen for login.
                         $this-&gt;layout = 'offline';  
                         $this-&gt;setFlash('Maintenance Mode. Check back shortly.');
                         $this-&gt;Auth-&gt;deny('*');
                     }
                }
  
            }
  
         }
   ?&gt;
  </code></pre>
  
  <p>Then I used jQuery to hide my login form. An admin clicks on the message to show the login form. This is an attempt to prevent any login tryouts.</p>
  
  <p>============================ END EDIT ==========================================</p>
  
  <p>I would like to know what is the best way to create a "site offline/online" feature in CakePHP. Basically, I would like to allow an administrator to turn off access to the site to everyone registered or not. The offline page should have a login access thru which only admins can login.</p>
  
  <p>The idea I have is to create some kind of dashboard controller, where as soon as the administrator is logged in he/she will be redirected to this dashboard from where he can access the other controller actions (admin_edit, etc). This dashboard and all admin actions (admin_delete, etc) should use the admin layout. </p>
  
  <p>Is this a good approach? For the offline/online feature should I create a settings table with a site_offline field that can be turned on or off? Where in app_controller and what code should I use to check for it before allowing or not access to the site?</p>
  
  <p>Thanks a lot for your help,</p>