一,项目中启用session
1,app/middleware.php 添加如下一行//Session初始化 \think\middleware\SessionInit::class
2,注意给runtime目录加入写权限:
例:
liuhongdi@lhdpc:/data/php/admapi$ chmod 777 runtime/
说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
或: https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,写入到session以及从session读取代码
//引入session类 use think\facade\Session; ... //获取session public function getsession() { //指定key $name = Session::get('name'); //全部 $all = Session::all(); return Result::Success($all); } //设置session public function setsession() { Session::set('name', '老刘'); $name = Session::get('name'); return Result::Success($name); }
三,测试效果
设置session读取session
四,查看thinkphp的版本:
liuhongdi@lhdpc:/data/php/admapi$ php think version v6.0.10LTS
标签:v6.0,name,Session,liuhongdi,10LTS,thinkphp6,session,php,com From: https://www.cnblogs.com/architectforest/p/17164736.html