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

相关推荐
qq3186929961 天前
ThinkPHP + Supervisor 队列任务丢失:僵尸 Worker 排查全记录
服务器·thinkphp·宝塔
linlinlove21 天前
前端uniapp、后端thinkphp股票系统开发功能展示、代码披露、HQChart
前端·uni-app·echarts·thinkphp·hqchart·配资·deepseek选股票
SuperherRo21 天前
服务攻防-开发框架安全&ThinkPHP&Laravel&SpringBoot&Struts2&SpringCloud&复现
spring boot·laravel·thinkphp·struts2·框架安全
quweiie23 天前
thinkphp8生成海报
thinkphp·海报
云游云记2 个月前
FastAdmin 路由完全开启教程:去掉 index 前缀 + 优雅路由配置
thinkphp
kertag2 个月前
ThinkPHP 8 多应用入口绑定:BIND_MODULE vs $http->name() 全面解析
php·thinkphp
妙码生花2 个月前
全新的 TP8+Workerman+BuildAdmin 整合方案,已有近 2000 次下载使用。
websocket·php·thinkphp
quweiie2 个月前
在php8.3下签到、签退打卡的实现
thinkphp·签到·nesbot/carbon
天宁4 个月前
Workerman + ThinkPHP 8 结合使用
php·thinkphp
云游云记4 个月前
ThinkPHP 队列扩展 (topthink/think-queue) 使用笔记
php·thinkphp·think-queue