public static function getConfigValue($id) { $model = Config::findOne(['id' => $id]); if ($model === null) { return '不存在配置项:' . $id; } return $model->value; }
public static function getModel($id, $fromCache = true) { $cacheKey = self::CachePrefix . $id; $value = $fromCache ? LuLu::getCache($cacheKey) : false; if ($value === false) { $value = Config::findOne(['id' => $id]); if ($value !== null) { LuLu::setCache($cacheKey, $value); } } return $value; }
/** * 初始使值 * @param type $model * @param type $attributes * @return type */ public static function initValueInternal($model, $attributes) { if ($attributes) { foreach ($attributes as $key) { $cmodel = Config::findOne(['`key`' => $key]); if ($cmodel) { $model->{$key} = $cmodel->value; } } } return $model; }
protected function initOneInternal($id, $defaultValue = '') { $model = Config::findOne(['id' => $id]); if ($model != null) { $this->{$id} = $model->value; } else { if (empty($defaultValue) && $this->{$id} !== null) { $defaultValue = $this->{$id}; } $model = new Config(); $model->id = $id; $model->value = $defaultValue; $model->save(); $this->{$id} = $defaultValue; } }
public static function getConfig($key) { $model = Config::findOne(['`key`' => $key]); return empty($model) ? '' : $model->value; }