예제 #1
0
파일: Setting.php 프로젝트: jorry2008/turen
 /**
  * 更新配置缓存
  * @return boolean
  */
 public function updateCache()
 {
     $cache = Yii::$app->getCache();
     $models = Setting::find()->all();
     //整个缓存表,包括不可见内容
     //处理数组形式的数据
     foreach ($models as $key => $model) {
         if ($model->is_array) {
             $values = explode(',', $model->value);
             $newValues = [];
             if ($values) {
                 foreach ($values as $value) {
                     $v = explode('=>', $value);
                     $newValues[$v[0]] = $v[1];
                 }
             }
             $models[$key]->value = $newValues;
         }
     }
     $data = Json::encode(ArrayHelper::map($models, 'key', 'value'));
     //获取数据
     if ($cache->exists(self::CACHE_KEY)) {
         $cache->delete(self::CACHE_KEY);
     }
     $cache->set(self::CACHE_KEY, $data);
     return true;
 }
예제 #2
0
 protected function findAuthItemModel($id)
 {
     if (($model = Setting::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }