lumen5.4设置cookie
use Illuminate\Support\Facades\Cookie; use Symfony\Component\HttpFoundation\Cookie as SCookie; //自定义response并设置cookie public function index() { $r = Cookie::get('qqmail_alias'); //var_dump($r); return response('this is test') ->withCookie(new SCookie('sid', 'sid9999', time()+3600)) ->withCookie(new SCookie('uid', 'uid9999', time()+3600)); }
如何返回视图并设置cookie,view助手函数返回的html字符串传给response助手函数
注意Symfony\Component\HttpFoundation\Cookie的构造函数的中的过期时间的用法,
不能只传3600秒,需要传一个未来的时间戳,或者是一个对象,具体要仔细看类代码
public function index() { $r = Cookie::get('qqmail_alias'); $data = [ ]; return response(view('user.index', $data)) ->withCookie(new SCookie('xxid', 'sid8888', time()+3600)) ->withCookie(new SCookie('yyid', 'uid9999', time()+3600)); }
控制器代码如上所示
posted on 2017-05-31 13:07 dongruiha 阅读(2144) 评论(0) 编辑 收藏 举报