在OpenCart中這樣做並不是一個好方法。這就是說,這裏的骯髒的方式:
創建您的根目錄裏面(如果數據庫連接失敗,這將被載入)以下一個maintenance.php
:在/system/database/mysql.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
方法是:
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);
}
是的,這是可能的。 'index.php'中有一個鉤子,用於檢查*維護模式*是否打開。在你的'index.php'中你應該檢查與數據庫的連接是否成功,如果不是,你應該立即手動切換到維護模式。您可以通過包含維護模式模板和退出運行時來完成此操作。但是我建議只在生產環境中使用該解決方案,在您的本地上您應該明智地考慮可能發生的任何錯誤。 – shadyyx