我想在我的网站上进行维护模式,我想放一个只有管理员才能看到的按钮来打开/关闭维护模式.
这允许管理员继续看到网络但其他访问者没有.
我已经阅读了关于catchAllRequest,创建文件并在必要时重命名它,但我不能让它工作.
我试过underconstruct扩展,但我不知道如何切换ON/OFF.
这就是我现在所拥有的.
控制器:
public function actionIndex()
{
$location = Yii::app()->request->baseUrl.'/protected/config/maintenanceON.txt';
$new = Yii::app()->request->baseUrl.'/protected/config/maintenanceOFF.txt';
Yii::app()->session['secret'] = "password";
rename($location,$new);
$this->renderPartial("index");
}
Run Code Online (Sandbox Code Playgroud)
CONFIG/MAIN.PHP:
'catchAllRequest'=>file_exists(
dirname(__FILE__).'/maintenanceON.txt') &&
!(isset(Yii::app()->session['secret']) && Yii::app()->session['secret']=="password") ?
array('maintenance/index') : null,
Run Code Online (Sandbox Code Playgroud)
谢谢!