views:

475

answers:

6

I'm trying to figure out how to set up a holding/"under maintenance" page in Zend Framework for when I am upgrading the database or something and don't want anyone using the site. I'd like to have a static HTML page and have all traffic redirected to that.

I'd rather not use .htaccess and would like to do it via the bootstrap file.

Any ideas?

Thanks.

+1  A: 

You could check your configuration file for a maintenance_mode switch and redirect every request from within the bootstrap to your static html maintenance page.

Stefan Gehrig
+1  A: 

I've done this by creating a plugin that check the validity of the request each time that a page is requested.

During the execution of the plugin in the "preDispatch()" you can analyze a variable from the config that it will hold your current status as active/under maintenance and let the request flow to the original destination or redirect it to a landing page for this purpose.

Elzo Valugi
A: 

Here's my little hack, comment it out when it's not needed:

//in your bootstrap.php
session_start();
if(0 === strcmp($_GET['mode'],'maintenance')) {
   $_SESSION['mode'] = 'maintenance';
}
if(!isset($_SESSION['maintenance'])) {
    die('Maintenance is underway. Please check back later');
}

Make a single request to your site with that GET param set, e.g.:

/foo/?mode=maintenance

and everyone but you will be blocked out and get your message. Of course, you could always just include a pretty HTML page instead.

karim79
+1  A: 

I've set Apache to show index.html in preference to index.php (which bootstraps the ZF). As long as you don't link directly to /index.php anywhere, then you can just drop in an index.html file, and it will show that in preference to the ZF site.

An alternative is to have an entry in your configuration .ini file, and as soon as you have read the configuration:

if ($config->maintenance) {
    readfile(APPLICATION . '/../public/maintenance.html');
    exit;
}

You may want to add another check in there for a particular IP address (your own) as well, so that you can get though even when everyone else is blocked.

Alister Bulman
A: 

I would use plugin with dispatchLoopShutdown() and based on the config settings i would redirect the request to any controller you want.

Tomáš Fejfar
A: 

I have a blog post that demonstrates how to do this. Setting up a maintenance page with Zend Framework

Kevin Schroeder
@WebinarsatZend has already tweet about your blogpost http://twitter.com/WebinarsatZend/status/12526221389
tawfekov