code走起来。
namespaceApp\Http\Controllers;
useIlluminate\Http\Request;
classSessionControllerextendsController
{
//关于session操作
public functiongetTest()
{
dd(session('key'));
}
/**
*获取session全局辅助函数session(); http实例Request
*/
public functiongetSession(Request$request)
{
//read
$m=session('sl','ls');var_dump($m);//dd(session('sl'));
$value=$request->session()->get('key','default');//全局session();
//session('key','ss'); var_dump(session('key'));
//session(['name'=>'name']);
$data=$request->session()->all();print_r($data);
//判断
if($request->session()->has('_token'))
{
echo'_token';//key存在且不为null
}
session(['test'=>null]);
if($request->session()->exists('test'))
{
echo'exists';//key存在可能为null
}
//insert
$request->session()->put('xiao','ming');//单个数据
$request->session()->put(['xiao'=>'xiao','ming'=>'ming']);//多个数据
$request->session()->push('arr.a','arra');//多维数组
//dd($request->session()->get('arr')['a']);
//dd(session('arr')['a'][0]);
//delete
$delete=$request->session()->pull('xiao');//delete单个值 并且得到该值
var_dump($delete);
$request->session()->forget('ming');//不会得到删除的值//$delete1=
//var_dump($delete1);
$request->session()->flush();//删除所有的session //$arrDelete=
//var_dump($arrDelete);
//其他
$request->session()->flash();
$request->session()->reflash();
$request->session()->keep();
$request->session()->regenerate();//重新生成一个sessionId;
var_dump($request->session()->all());
echo'put
';var_dump(session('xiao'));echo'
';
dd($value);
}
public functiongetRequest(Request$request)
{
//insert
if($request->session=='insert')
{
$value=session('key','valuez');//?time? 1指定默认值 并不是赋值
$arrValue=session(['key'=>'sessionrequest']);//insert 2 arr就是赋值 即存值
dd($arrValue);//null
//dd(session('key'));
echosession('key');dd($value);//
}
//read
if($request->session=='read')
{
$value=session('key');
dd($value);
}
//delete
if($request->session=='delete')
{
}
}
}
网友评论