Skip to content

Commit

Permalink
修复config编辑sql版本不同报错问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ailaohuniu committed Jan 19, 2022
1 parent 10d9e7c commit b3533a5
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions app/common/model/Config.php
Expand Up @@ -20,26 +20,30 @@ class Config extends Model
protected $updateTime = false;
// 追加属性
protected $append = [
'extend_html'
];
protected $type = [
'setting' => 'json',
'extend_html',
'setting',
];

public static function onBeforeWrite($row)
public function getSettingAttr($value, $data)
{
if (isset($row['name']) && $row['name'] == 'name' && preg_match("/fast" . "admin/i", $row['value'])) {
throw new Exception(__("Site name incorrect"));
}
if (isset($row['setting']) && !$row['setting'] ) {
$row->setting ='';
$value = $value ? $value : ($data['setting'] ?? '');
if ($value){
$arr = json_decode($value, true);
}else{
$arr = [];
}
return $arr;
}

public static function onBeforeUpdate($row)
protected function setSettingAttr($value)
{
if (isset($row['setting']) && !$row['setting'] ) {
$row->setting ='';
return $value ? json_encode($value, JSON_UNESCAPED_UNICODE) : '';
}

public static function onBeforeWrite($row)
{
if (isset($row['name']) && $row['name'] == 'name' && preg_match("/fast" . "admin/i", $row['value'])) {
throw new Exception(__("Site name incorrect"));
}
}

Expand Down

0 comments on commit b3533a5

Please sign in to comment.