PHP code example of insolita / yii2-maintenance

1. Go to this page and download the library: Download insolita/yii2-maintenance library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

insolita / yii2-maintenance example snippets


     'bootstrap'=>['log','config','maintenance'],
     'container'=>[
     ...
         'definitions'=>[
             '\insolita\maintenance\IConfig'=>'your\config\component\class'
         ]
     ],
     ...
     'components'=>[
          'maintenance'=>[
              'class'=>'\insolita\maintenance\Maintenance',
              'enabledKey'=>'config key for maintennce indication',
              'preliminarKey'=>'config key for preliminar maintenance indication',
              'ipSkippedKey'=>'config key for comma-seperated ips with exclusive access',
              'catchRoute'=>['site/maintenance'], //- route catched all requests in maintenance mode
              //possible events use cases
              'on maintenance_process'=>function($event){
                  //$event->sender is maintenance component!
                  if($event->sender->isSkipForIp===true){
                     Yii::$app->getSession()->setFlash('warning','Site in maintenance mode!');
                  }
              },
              'on maintenance_soon'=>function($event){
                  Yii::$app->getSession()->setFlash('warning',
                  'After 5 minutes, the site will be serviced, please finish or save the undelivered messages');
               }
          ]
     ],