使用thinkorm,字段content是存的數(shù)組序列化后的值,模型加了獲取器的
獲取器:
public function getContentAttr($value)
{
return $value ? unserialize($value) : [];
}
模型方法:
public function getConfig($id = null)
{
$id = $id ?? request()->get('id') ;
if(! $id) abort('參數(shù)錯(cuò)誤');
$data = $this->cache(true)->where('id',$id)->field('content')->find();
return $data['content'] ?? [];
}
只有第一次調(diào)用會(huì)報(bào)錯(cuò),如果把緩存去了就不會(huì)報(bào)錯(cuò):
如果把模型方法改成這樣:
public function getConfig($id = null)
{
$id = $id ?? request()->get('id') ;
if(! $id) abort('參數(shù)錯(cuò)誤');
//修改了這,把find改為value
$data = $this->cache(true)->where('id',$id)->value('content');
return $data ?? [];
}
這樣問(wèn)題就更大了,查詢出來(lái)$data等于null,更別說(shuō)緩存了
thinkcache.php設(shè)置調(diào)加:'serialize' => ['serialize', 'unserialize']試一試,好像是thinkcache兼容性問(wèn)題,你PHP版本降低看看 如7.4