问题描述
我试图实现使用CakePHP 2.1.0。我很接近实现这一点,但我遇到两个问题,我可以使用一些帮助。首先,这里是所有相关的代码(六个文件):
I'm trying to implement something like Mark Story's "Down for Maintenance" page using CakePHP 2.1.0. I'm pretty close to achieving this, but I'm running into two issues that I could use some help with. First of all, here is all of the relevant code (six files):
1)app / Config / bootstrap.php:
1) app/Config/bootstrap.php:
Configure::write('App.maintenance', true);
2)app / Config / core.php:
2) app/Config/core.php:
Configure::write('debug', 1);
...
Configure::write('Exception', array(
'handler' => 'ErrorHandler::handleException',
'renderer' => 'AppExceptionRenderer',
'log' => true
));
3)app / Controller / AppController.php:
3) app/Controller/AppController.php:
if (Configure::read('App.maintenance') == true) {
App::uses('DownForMaintenanceException', 'Error/Exception');
throw new DownForMaintenanceException(null);
}
$ b $ p 4)app / Lib / Error / Exception / DownForMaintenanceException.php: p>
4) app/Lib/Error/Exception/DownForMaintenanceException.php:
<?php
class DownForMaintenanceException extends CakeException {}
5)app / Lib / Error / AppExceptionRenderer.php:
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)app / View / Errors / down_for_maintenance.ctp :
6) app/View/Errors/down_for_maintenance.ctp:
<p>Down for Maintenance</p>
现在,对于我遇到的两个问题。首先,这个代码只有当调试设置高于1时才有效。有什么我可以做的吗?这是否表明我要这个错误的方式?第二个问题是,虽然我在downForMaintenance方法中将isMobile和logged_in视图变量设置为 boolean 值,但是app / View / Layouts / default.ctp文件将其视为字符串。我可以做些什么?
Now, for the two issues I'm experiencing. First, this code only works when debug is set higher than 1. Is there anything I can do about that? Does that indicate that I'm going about this the wrong way? The second issue is that, although I'm setting the "isMobile" and "logged_in" view variables to boolean values in the "downForMaintenance" method, the "app/View/Layouts/default.ctp" file is seeing them as strings. What can I do about that?
谢谢!
推荐答案
是cakephp的快速和脏的维护页面
here is a quick and dirty maintenance page for cakephp
in public index.php
in public index.php
define('MAINTENANCE', 0);
if(MAINTENANCE > 0 && $_SERVER['REMOTE_ADDR'] !='188.YOUR.IP.HERE')
{
require('maintenance.php'); die();
}
然后只需要更改MAINTENANCE = 1,仍然可以从您的家/办公室查看。
Then just change MAINTENANCE = 1 when you want to take your site down and it will still be viewable from your home/office.
奖金:适用于所有版本的蛋糕!
BONUS: Works with all versions of cake!
这篇关于CakePHP 2.1.0:如何创建“下来维护”页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!