예제 #1
0
 /**
  * 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]);
 }
예제 #2
0
 public function down()
 {
     $this->dropTable(Config::tableName());
 }
예제 #3
0
 /**
  * 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();
         }
     }
 }
예제 #4
0
 /**
  * Insert configuration parameter.
  * @param array $param Parameter from $config.
  * @return integer
  */
 protected function insert(array $param)
 {
     foreach (['rules', 'options'] as $binary) {
         if (isset($param[$binary])) {
             $param[$binary] = serialize($param[$binary]);
         }
     }
     return Yii::$app->db->createCommand()->insert(Config::tableName(), $param)->execute();
 }