手冊中行為有幾種實現方法
這里我說一種我用的,
tags.php文件中配置
<?php
// 應用行為擴展定義文件
return [
// 應用初始化
'app_init' => [
],
// 應用開始
'app_begin' => [
],
// 模塊初始化
'module_init' => [],
// 操作開始執行
'action_begin' => [
'app\\common\\behavior\\ActionBegin'
],
// 視圖內容過濾
'view_filter' => [],
// 日志寫入
'log_write' => [],
// 應用結束
'app_end' => [],
];
我是在操作開始執行的時候有判斷(因為我要取執行模塊),在applocation應用目錄中建立common文件夾,common中建立behavior文件夾,behavior中建立ActionBegin.php文件
ActionBegin.php文件中配置
<?php
namespace app\common\behavior;
use think\Controller;
/**
* Created by PhpStorm.
* User: lycbl
* Date: 2017/2/14
* Time: 18:22
*/
class ActionBegin extends Controller{
public function run() {
if(request()->module() == 'install'){
return true;
}else {
//自動安裝判斷
$lock_file = LOCK_PATH.'install.lock';
if(!file_exists($lock_file)){
$this->redirect(url('install/Index/index'));
exit;
}
}
}
}
這樣就可以了