/** * Set up value of parameter. * * @param string $module The name of module. * @param string $name The name of parameter. * @param mixed $value The new value of parameter. * @return boolean * @since 1.0.4 * @throws NotFoundParamException * @throws InvalidValueException */ public function set($module, $name, $value) { $param = Config::find()->byModule($module)->byName($name)->one(); if ($param === null) { throw new NotFoundParamException(Module::t('PARAMETER_NOT_FOUND', ['module' => $module, 'name' => $name])); } $param->value = $value; if (!$param->save(true, ['value'])) { throw new InvalidParamValueException(Module::t('INVALID_PARAMETER_VALUE', ['module' => $module, 'name' => $name])); } return $this->clearCache(); }
/** * 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]); }