tp6 获取session_TP6文档

本文档介绍了ThinkPHP6框架中关于请求变量的获取,包括`Request`类的使用,如`param()`、`header()`、`session()`、`cookie()`等方法,以及响应处理如`json()`、`jsonp()`、`xml()`、`redirect()`等。同时,还涵盖了路由、数据验证、数据库操作、模型、模板视图和日志记录等内容。
摘要由CSDN通过智能技术生成

请求变量

~~~

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值