在 OpenCart 中没有真正的好方法来做到这一点。也就是说,这是肮脏的方式:
在您的根目录中创建一个maintenance.php
,其中包含以下内容(如果数据库连接失败,则会加载该目录):
<?php
// Tell any crawlers visiting the site that it's currently unavailable
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 300');//300 seconds
?>
<html><body>
<h1>Sorry, the website is currently unavailable</h1>
...
...
</body></html>
__construct
将方法编辑/system/database/mysql.php
为:
public function __construct($hostname, $username, $password, $database) {
if (!$this->link = @mysql_connect($hostname, $username, $password)) {
exit(include(DIR_SYSTEM . '../maintenance.php'));
}
if (!mysql_select_db($database, $this->link)) {
exit(include(DIR_SYSTEM . '../maintenance.php'));
}
mysql_query("SET NAMES 'utf8'", $this->link);
mysql_query("SET CHARACTER SET utf8", $this->link);
mysql_query("SET CHARACTER_SET_CONNECTION=utf8", $this->link);
mysql_query("SET SQL_MODE = ''", $this->link);
}