thinkphp6 入门(8)-- Session

开启Session

Session功能默认是没有开启的(API应用通常不需要使用Session

复制代码
'think\middleware\SessionInit'

// 添加引用

复制代码
use think\facade\Session;

赋值

复制代码
Session::set('name', 'thinkphp');

取值

复制代码
// 如果值不存在,返回null
Session::get('name');
// 如果值不存在,返回空字符串
Session::get('name', '');
// 获取全部数据
Session::all();

删除

复制代码
Session::delete('name');

取值并删除

复制代码
// 取值并删除
Session::pull('name');

如果name的值不存在,返回Null

清空

复制代码
Session::clear();

原文:Session · ThinkPHP6.0完全开发手册 · 看云ThinkPHP`6.0`基于精简核心和统一用法两大原则在`5.1`的基础上对底层架构做了进一步的优化改进,并更加规范化。 https://www.kancloud.cn/manual/thinkphp6_0/1037635

相关推荐
quweiie2 天前
thinkphp8生成海报
thinkphp·海报
云游云记1 个月前
FastAdmin 路由完全开启教程:去掉 index 前缀 + 优雅路由配置
thinkphp
kertag1 个月前
ThinkPHP 8 多应用入口绑定:BIND_MODULE vs $http->name() 全面解析
php·thinkphp
妙码生花1 个月前
全新的 TP8+Workerman+BuildAdmin 整合方案,已有近 2000 次下载使用。
websocket·php·thinkphp
quweiie2 个月前
在php8.3下签到、签退打卡的实现
thinkphp·签到·nesbot/carbon
天宁3 个月前
Workerman + ThinkPHP 8 结合使用
php·thinkphp
云游云记3 个月前
ThinkPHP 队列扩展 (topthink/think-queue) 使用笔记
php·thinkphp·think-queue
用户14644605033794 个月前
PHP 多维数组处理利器:array_column() 用法详解
php·thinkphp
用户3074596982074 个月前
ThinkPHP 6.0 多应用模式下的中间件机制详解
后端·thinkphp
行思理4 个月前
小游戏系统提供二开服务
layui·游戏程序·小游戏·thinkphp