Example #1
0
 public static function getConfigValue($id)
 {
     $model = Config::findOne(['id' => $id]);
     if ($model === null) {
         return '不存在配置项:' . $id;
     }
     return $model->value;
 }
Example #2
0
 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;
 }
Example #3
0
 /**
  * 初始使值
  * @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;
 }
Example #4
0
 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;
     }
 }
Example #5
0
 public static function getConfig($key)
 {
     $model = Config::findOne(['`key`' => $key]);
     return empty($model) ? '' : $model->value;
 }