The "site down for maintenance" approach

I use Joomla and I like its administrative tool to host the site for maintenance. As I saw, all requests to the site, if it is in maintenance mode, are redirected to one page. If I want to add my own "site down for maintenance" module for a site without Joomla, how can I do this? I use the MVC framework in PHP called Kohana in its version 2, which is similar to Codeigniter. I have a Router class where I can control where a specific address goes. The only approach I can think of is to redirect each request to a specific controller function when the site is down, but how to do it? Can't I manually redirect all urls manually?

+5
source share
7 answers

Kohana 3 : You can define a catch-all route in bootstrap.phpfront of the lines Kohana::modules():

if (/* check if site is in under maintenance mode */) {
    Route::set('defaulta', '(<id>)', array('id' => '.*'))
        ->defaults(array(
            'controller' => 'errors',
            'action'     => 'maintenance',
        ));
}

Or you may even be asked to do the same:

if (/* check if site is in under maintenance mode */) {
    echo Request::factory('errors/maintenance')
        ->execute()
        ->send_headers()
        ->response;
}

Kohana 2 : You will need to expand Controllerand process the display of the page "for maintenance" in the constructor (but you must make sure that all your controllers extend this controller class instead of vanilla):

abstract class Custom_Controller extends Controller {

    public function __construct()
    {
        parent::__construct();
        if (/* check if site is in under maintenance mode */) {
            $page = new View('maintenance');
            $page->render(TRUE);
            exit;
        }
    }
}

Or you can even use the hook system to do this by adding the file to your folder hooks(make sure you turn on hooks in config.php):

Event::add('system.ready', 'check_maintenance_mode');

function check_maintenance_mode() {
    if (/* check if site is in under maintenance mode */) {
        Kohana::config_set('routes', array('_default' => 'errors/maintenance'));
    }
}

As you can see, there are actually many ways to do things in Cohan, because it is a very flexible PHP framework :)

+6
source

. , uri /. , .

+9

(, include, ..), , (, , ..).

+2

Apache? .htaccess - ( vhost ), - " ":

Redirect 301 / /maintenace_page.html

+1

index.php IN_MAINTENANCE

, , :

function in_maintenance()
{
    if(IN_MAINTENANCE)
    {
         Router::$controller = 'my_maintenance_controller';
         Router::$method = 'index';
    }
}

system.post_routing.

Event::add('system.post_routing', 'in_maintenance');

, IN_MAINENANCE TRUE, .

. Event/ .

0

Another way to switch is to check the file: if it exists, maintenance starts, so turn off the site.

If so, you can do any of the above.

0
source

All Articles