CodeIgniter Forums
under maintenance - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: under maintenance (/showthread.php?tid=83497)



under maintenance - pippuccio76 - 09-30-2022

Which is the best and simple way to set site under maintenance ? (redirecting to a view)


RE: under maintenance - superior - 09-30-2022

Creating a filter in my opinion, or https://github.com/arashsaffari/maintenancemode


RE: under maintenance - pippuccio76 - 10-05-2022

I found this solution , in view i create a specific view ( under_maintenance.php)  directly under view  . 
In home or other controller create a function:
Code:
public function under_maintenance()
    {
        return view('under_maintenance');

    }

in route
Code:
<?php
namespace Config;

// Create a new instance of our RouteCollection class.
$routes = Services::routes();

// Load the system's routing file first, so that the app and ENVIRONMENT
// can override as needed.
if (is_file(SYSTEMPATH . 'Config/Routes.php')) {
    require SYSTEMPATH . 'Config/Routes.php';
}

//variabile in manutenzione
$under_maintenance = 1;



/*
* --------------------------------------------------------------------
* Router Setup
* --------------------------------------------------------------------
*/
$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('User');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override();


//route under maintenance
if($under_maintenance){

$routes->get('(:any)', 'Home::under_maintenance');

}else{   

//all other roules
}


there could be problems using this way?


RE: under maintenance - kenjis - 10-05-2022

HTTP status code.


RE: under maintenance - pippuccio76 - 10-06-2022

(10-05-2022, 03:26 PM)kenjis Wrote: HTTP status code.
what does it mean ?


RE: under maintenance - kenjis - 10-06-2022

The HTTP status code of the maintenance page would be 200.
It may be cached by search engines.


RE: under maintenance - davis.lasis - 10-06-2022

Problem: i have multiple routes files
I have created app with multiple modules, therefore each module has it's own routes file

I use filter for maintenance, but novadays we must echo the response in filter's before() method
PHP Code:
// Filter
public function before(RequestInterface $request$arguments null)
{
      if (!empty(getenv('maintenance'))) {
          echo FrontendMaintenanceController::maintenance();
          exit();
      }
}

// FrontendMaintenanceController
public static function maintenance()
{
    $maintenance getenv('maintenance');

    if (empty((string) $maintenance)) {
        return redirect()->route('frontend-homepage');
    }

    return view(service('settings')->get('FrontendSettings.theme_path').'Base/maintenance', ['deadline' => $maintenance]);




RE: under maintenance - ikesela - 10-06-2022

use existing package, very convenience: 
arashsaffari/maintenancemode

just modify the maintenancemode  controller to choose which to set in maintenance mode.
Code:
public static function check() { .. }



RE: under maintenance - davis.lasis - 10-07-2022

(10-06-2022, 11:38 PM)ikesela Wrote: use existing package, very convenience: 
arashsaffari/maintenancemode

just modify the maintenancemode  controller to choose which to set in maintenance mode.
Code:
public static function check() { .. }

Hi,
i did look at that repo, but it is really old and did not suit my needs.
So i created my own approach using filter though