我使用的是最新的 codeigniter,我需要创建一个标志(最好在配置中),当它变为“true”时,所有页面都会显示“维护模式”消息,而不是执行它们的 Controller 代码。
执行此操作的最佳/最简单做法是什么?
最佳答案
这是我的解决方案,对我来说效果很好:
下面会立即调用 maintanance.php,这样你就可以在不让外界看到的情况下继续破解你的 CI 代码。
还允许您添加自己的 IP 地址,以便您仍然可以访问该站点进行测试等。
在 index.php 顶部添加:
$maintenance = false; ## set to true to enable
if ($maintenance)
{
if (isset( $_SERVER['REMOTE_ADDR']) and $_SERVER['REMOTE_ADDR'] == 'your_ip')
{
##do nothing
} else
{
error_reporting(E_ALL);
ini_set('display_errors', 1); ## to debug your maintenance view
require_once 'maintenance.php'; ## call view
return;
exit();
}
}
在与 index.php 相同的文件夹中添加文件 Maintanance.php(或上面的更新路径):
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Maintenance</title>
<style>
body {
width:500px;
margin:0 auto;
text-align: center;
color:blue;
}
</style>
</head>
<body>
<img src="images/home_page_logo.png">
<h1><p>Sorry for the inconvenience while we are upgrading. </p>
<p>Please revisit shortly</p>
</h1>
<div></div>
<img src="images/under-maintenance.gif" >
</body>
</html>
<?php
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 3600');
?>
关于php - 如何在 Codeigniter 中构建 'maintenance mode'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15572568/