請求變量
use think\facade\Request;
Request::param('name');
Request::param();全部請求變量 返回數組
Request::param(['name', 'email']); 多個變量
Request::param('a','1') $a不存在使用默認值1
Request::param('username','','strip_tags'); 參數過濾 去掉html標簽 htmlspecialchars轉換成實體入庫 strtolower小寫
Request::header(); 請求頭數組,支持單個 cookie
input("name");
Request::session();獲取 $_SESSION 變量
Request::cookie();獲取 $_COOKIE 變量
Request::server();獲取 $_SERVER 變量
Request::env();返回env數組
Request::file();獲取 $_FILES 變量
Request::baseUrl(); /index/index
Request::host(true); 域名:www.baidu.com,默認無參數包含端口:80
Request::url(1); 完整域名和地址 http://tp6.api.shanliwawa.top:80/index/index
Request::domain(1) http://tp6.api.shanliwawa.top
Request::time() 請求時間戳
Request::app() 應用名 index
Request::controller() 控制器 Index 參數true小寫
Request::action() 操作 index 參數true 小寫
Request::method(true); 請求類型獲取 GET
isGet isPost isPut isDelete isAjax isMobile isHead 判斷是否某種類型
Request::has('id','get'); 檢測變量id是否存在
url('index/hello', ['id'=>5,'name'=>'李白'],'do'); http://tp6.api.shanliwawa.top/index/hello/李白.do?id=5
url('index/hello#aa'); 錨點
Cache::set('name', $value, 3600); 1小時后過期
Cache::get('name'); 獲取緩存
多緩存類型配置
return [
// 緩存類型為File
'type' => 'redis',
// 全局緩存有效期(0為永久有效)
,開發下一定要設置-1 否在刷新后 還在
'expire'=> -1,
// 緩存前綴
'prefix'=> 'think',
// 緩存目錄
'host' => '127.0.0.1',
];
return [
// 使用復合緩存類型
'type' => 'complex',
// 默認使用的緩存
'default' => [
// 驅動方式
'type' => 'file',
// 緩存保存目錄
'path' => '../runtime/default',
],
// 文件緩存
'file' => [
// 驅動方式
'type' => 'file',
// 設置不同的緩存保存目錄
'path' => '../runtime/file/',
],
// redis緩存
'redis' => [
// 驅動方式
'type' => 'redis',
// 服務器地址
'host' => '127.0.0.1',
],
];
use think\facade\Cache;
Cache::store('file')->set('name','123',0);
$v = Cache::store('redis')->get('name');
Cache::store('default')->get('name');文件緩存
Cache::delete('name');
Cache::clear();
Cache::set('name', [1,2,3]);
Cache::push('name', 4);
Cache::remember('start_time', time()); 不存在則創建
Cache::inc('name',1); 自增1
Cache::dec('name',1); 自減1
$redis = Cache::handler(); redis對象
配置redis session
return [
'type' => 'redis',
'prefix' => 'think',
'auto_start' => true,
// redis主機
'host' => '127.0.0.1',
// redis端口
'port' => 6379,
// 密碼
'password' => '',
]
session('name', ['thinkphp']); 設置支持字符串 數組
session('name');獲取
session('name', null);刪除
session(null);清空
cookie('name', 'value', 3600);
設置不支持數組,序列化后存儲
cookie('name');
cookie('name', null);
cookie('think_lang','en-us');//設置語言類型
lang('add user error');//翻譯
config('cache.type') 讀取配置