mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-07-01 16:22:49 +08:00
fix(api): 修复getData(id)新建对象时抛异常,改用isset安全检查
This commit is contained in:
@@ -270,11 +270,12 @@ class Post extends Base
|
||||
public function getHitsTitleAttr()
|
||||
{
|
||||
// 新建对象时直接返回 0
|
||||
$id = $this->getData('id');
|
||||
if (empty($id)) {
|
||||
if (!isset($this->data['id']) || empty($this->data['id'])) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$id = $this->data['id'];
|
||||
|
||||
$cache_key = static::CACHE_KEY_HITS . $id;
|
||||
|
||||
$value = Cache::get($cache_key);
|
||||
@@ -294,11 +295,12 @@ class Post extends Base
|
||||
public function setHitsAttr($value)
|
||||
{
|
||||
// 新建对象(无 id)时,直接返回值,跳过缓存操作
|
||||
$id = $this->getData('id');
|
||||
if (empty($id)) {
|
||||
if (!isset($this->data['id']) || empty($this->data['id'])) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$id = $this->data['id'];
|
||||
|
||||
$cache_key = static::CACHE_KEY_HITS . $id;
|
||||
|
||||
Cache::inc($cache_key);
|
||||
|
||||
Reference in New Issue
Block a user