Creating a Maintenance Page In the Zend Framework
One of the things that I love to do is to have a maintenance page so when we're doing something that could potentially break the site, like changing the database schema, we can keep the users from using the site until it's ready. In this vein, it's nice to be able to have a quick way to do this using the Zend Framework.
Creating the Plugin/The Heavy Lifter
This is a really simple process. Create a new plugin (I'm calling mine Speedy_Plugins_Maintenance because I'm making it part of the Speedy Library) and fill it with the following:
class Speedy_Plugins_Maintenance extends Zend_Controller_Plugin_Abstract{
public function routeShutdown(Zend_Controller_Request_Abstract $request){
// we only want to run this if the isMaintenance flag is set
if(is_file(dirname(APPLICATION\_PATH) . '/tmp/inMaintenance')){
$request->setModuleName('default');
$request->setControllerName('maintenance');
$request->setActionName('index');
}
}
}
The trick behind this is that we want to be easy to enable and disable so we're going to check for the existence of a file.
Getting This Working in the Application
In your bootstrap.php file add the following:
protected function _initEnablePlugins(){
$front = Zend_Controller_Front::getInstance();
$front->registerPlugin(new Speedy_Plugins_Maintenance());
}
This will add the Plugin to the Front Controller and run it. The last step is to create the MaintenanceController and the associated .phtml files. They're very bland so I won't go through them here. I would suggest you don't rely on the layout you currently have on the site because it might be inaccessible due to the maintenance.
Scott Keck-Warren
Scott is the Director of Technology at WeCare Connect where he strives to provide solutions for his customers needs. He's the father of two and can be found most weekends working on projects around the house with his loving partner.
Top Posts
- Working With Soft Deletes in Laravel (By Example)
- Fixing CMake was unable to find a build program corresponding to "Unix Makefiles"
- Upgrading to Laravel 8.x
- Get The Count of the Number of Users in an AD Group
- Multiple Vagrant VMs in One Vagrantfile
- Fixing the "this is larger than GitHub's recommended maximum file size of 50.00 MB" error
- Changing the Directory Vagrant Stores the VMs In
- Accepting Android SDK Licenses From The OSX Command Line
- Fixing the 'Target class [config] does not exist' Error
- Using Rectangle to Manage MacOS Windows