/** * 更新配置缓存 * @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; }
protected function findAuthItemModel($id) { if (($model = Setting::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }