tp5.1设置session

<?php
namespace app\index\controller;

use think\Container;
use think\facade\Env;
//引入自定义类 或者 第三方类库
use demo\MyDemo;
use app\org;
use think\facade\App;
use think\facade\Cache;
use think\session;
use think\facade\Session as SS;

class Index
{
        public function getFaced()
        {
            //方法1:用app()方法实例化类(绑定类到容器)
            $res = app('session');
            $res->set('k','java');
            $res->clear();
            $res = $res->get('k');

            //方法2:new 一个对象方式
            $s = new Session();
            $s->set('kk','vv');
            $s->clear();
            $res = $s->get('kk');

            //方法3:助手函数
            session('kkk','vvv');
            $res = session('kkk');

            //方法4:facade门面方式静态调用
            SS::set('k2','v2');
            $res = SS::get('k2');


            echo '<pre>';
            print_r($res);
        }
}

猜你喜欢

转载自blog.csdn.net/shj_php/article/details/88189363