Welcome Guest, Not a member yet? Register   Sign In
under maintenance
#1

(This post was last modified: 09-30-2022, 03:58 AM by pippuccio76.)

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

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

(This post was last modified: 10-05-2022, 12:33 PM by pippuccio76.)

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?
Reply
#4

HTTP status code.
Reply
#5

(This post was last modified: 10-06-2022, 10:22 AM by pippuccio76.)

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

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

(This post was last modified: 10-06-2022, 10:52 PM by davis.lasis.)

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]);

Reply
#8

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() { .. }
Reply
#9

(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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB