Kohana 3:
您可以在 bootstrap.php 中 Kohana::modules() 行之前定义一条包罗万象的路线:
if (/* check if site is in under maintenance mode */) {
Route::set('defaulta', '(<id>)', array('id' => '.*'))
->defaults(array(
'controller' => 'errors',
'action' => 'maintenance',
));
}
或者你甚至可以处理做同样事情的请求:
if (/* check if site is in under maintenance mode */) {
echo Request::factory('errors/maintenance')
->execute()
->send_headers()
->response;
}
Kohana 2:
您需要扩展 Controller 并处理构造函数中的“维护中”页面显示(但您需要确保所有控制器都扩展此控制器类而不是原始控制器类):
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;
}
}
}
或者您甚至可以使用挂钩系统来执行此操作,方法是在您的 hooks 文件夹中添加一个文件(确保在您的 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'));
}
}
如您所见,实际上在 Kohana 中有很多方法可以做事,因为它是一个非常灵活的 PHP 框架 :)