时间:2021-07-01 10:21:17 帮助过:3人阅读
session使用注意点
laravel是一款php框架了,在使用laravel时会碰到session使用问题,工作中使用的是session默认的文件缓存,在使用过发现 session()->put("key","values") 没有设置成功,最后翻源码发现是使用文件缓存时候需要使用save() 方法才能持久化到数据库中
源码:vendor/laravel/framework/src/Illuminate/Session/Store.php
/**
* Save the session data to storage.
*
* @return bool
*/
public function save()
{
$this->ageFlashData();
$this->handler->write($this->getId(), $this->prepareForStorage(
serialize($this->attributes)
));
$this->started = false;
}由于使用文件缓存 因此write方法调用的源码:vendor/laravel/framework/src/Illuminate/Session/FileSessionHandler.php
/**
* {@inheritdoc}
*/
public function write($sessionId, $data)
{
$this->files->put($this->path.'/'.$sessionId, $data, true);
return true;
}相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!
推荐阅读:
thinkphp5 migrate数据库迁移使用详解
php命名空间使用详解
以上就是Laravel 5.4.36中session保存失败如何处理的详细内容,更多请关注Gxl网其它相关文章!