gpt4 book ai didi

CakePHP 2.1.0 : How to Create "Down for Maintenance" Page

转载 作者:行者123 更新时间:2023-12-03 18:20:11 24 4
gpt4 key购买 nike

我正在尝试实现类似 Mark Story's "Down for Maintenance" page使用 CakePHP 2.1.0。我非常接近实现这一目标,但我遇到了两个问题,我可以使用一些帮助。首先,这里是所有相关代码(六个文件):

1)应用程序/配置/bootstrap.php:

Configure::write('App.maintenance', true);

2) 应用/配置/core.php:
Configure::write('debug', 1);

...

Configure::write('Exception', array(
'handler' => 'ErrorHandler::handleException',
'renderer' => 'AppExceptionRenderer',
'log' => true
));

3) 应用程序/ Controller /AppController.php:
if (Configure::read('App.maintenance') == true) {
App::uses('DownForMaintenanceException', 'Error/Exception');
throw new DownForMaintenanceException(null);
}

4) 应用程序/Lib/错误/异常/DownForMaintenanceException.php:
<?php
class DownForMaintenanceException extends CakeException {}

5) app/Lib/Error/AppExceptionRenderer.php:
<?php
App::uses('ExceptionRenderer', 'Error');

class AppExceptionRenderer extends ExceptionRenderer {
function _outputMessage($template) {
// Call the "beforeFilter" method so that the "Page Not Found" page will
// know if the user is logged in or not and, therefore, show the links that
// it is supposed to show.

if (Configure::read('App.maintenance') == false)
{
$this->controller->beforeFilter();
}

parent::_outputMessage($template);
}

public function downForMaintenance() {
$url = $this->controller->request->here();
$code = 403;
$this->controller->response->statusCode($code);
$this->controller->set(array(
'code' => $code,
'url' => h($url),
'isMobile' => $this->controller->RequestHandler->isMobile(),
'logged_in' => false,
'title_for_layout' => 'Down for Maintenance'
));
$this->_outputMessage($this->template);
}
}

6) 应用程序/ View /错误/down_for_maintenance.ctp:
<p>Down for Maintenance</p>

现在,对于我遇到的两个问题。首先,此代码仅在调试设置高于 1 时才有效。对此我能做些什么吗?这是否表明我正在以错误的方式解决这个问题?第二个问题是,尽管我在“downForMaintenance”方法中将“isMobile”和“logged_in” View 变量设置为 bool 值,但“app/View/Layouts/default.ctp”文件将它们视为字符串。我能做些什么呢?

谢谢!

最佳答案

这是 cakephp 的快速而肮脏的维护页面

在公共(public) index.php 中

define('MAINTENANCE', 0); 
if(MAINTENANCE > 0 && $_SERVER['REMOTE_ADDR'] !='188.YOUR.IP.HERE')
{
require('maintenance.php'); die();
}

然后,当您想要关闭您的网站时,只需更改 MAINTENANCE = 1,它仍然可以从您的家/办公室查看。

奖励:适用于所有版本的蛋糕!

关于CakePHP 2.1.0 : How to Create "Down for Maintenance" Page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9674696/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com