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',
));
}
Run Code Online (Sandbox Code Playgroud)
或者你甚至可以搞砸同样的要求:
if (/* check if site is in under maintenance mode */) {
echo Request::factory('errors/maintenance')
->execute()
->send_headers()
->response;
}
Run Code Online (Sandbox Code Playgroud)
Kohana 2:您需要扩展Controller和处理构造函数中的"维护不足"页面显示(但您需要确保所有控制器都扩展此控制器类而不是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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
或者您甚至可以通过在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'));
}
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,实际上有很多方法可以在Kohana中进行操作,因为它是一个非常灵活的PHP框架:)