ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
请求变量 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') 读取配置