/** * Display all config paramters for $byModule. * @return mixed */ public function actionIndex() { $models = Config::find()->where(['module' => $this->byModule])->orderBy(['id' => SORT_ASC])->indexBy('id')->all(); if (Model::loadMultiple($models, Yii::$app->request->post())) { if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validateMultiple($models, 'value'); } $result = true; foreach ($models as $model) { $result = $result && $model->save(true, ['value']); } if ($result && Module::getInstance()->configManager->clearCache()) { Yii::$app->session->setFlash('success', Module::t('SAVE_SUCCESS')); return $this->redirect(['index']); } } return $this->render('index', ['models' => $models]); }
/** * @inheritdoc */ public function init() { parent::init(); $this->params = Module::getInstance()->params; }
/** * Preparing parameters of config the application. */ protected function prepare() { if (!isset($this->_params)) { $module = Module::getInstance(); if ($module->enableCaching) { if (($this->_params = $module->cache->get([__CLASS__, 'params'])) === false) { $this->_params = Config::paramsArray(); $module->cache->set([__CLASS__, 'params'], $this->_params); } } else { $this->_params = Config::paramsArray(); } } }
/** * Unserialize 'options' field. * Unserialize and add rules of field. * Add label of fields. */ public function afterFind() { // unserialize 'options' field $options = unserialize($this->options); if ($options === false) { $options = []; } $this->options = $options; // unserialize and add rules of field $rules = unserialize($this->rules); if ($rules === false) { $rules = []; } foreach ($rules as &$rule) { array_unshift($rule, 'value'); } $this->_rules = $rules; // add label of fields $this->_labels = ['value' => Yii::t(Module::getInstance()->messageCategory, $this->label)]; // add hint of fields $this->_hints = ['value' => Yii::t(Module::getInstance()->messageCategory, $this->hint)]; parent::afterFind(); }