示例#1
0
 public function actionUpdate($name)
 {
     $post = Yii::$app->request->post();
     $item = $this->module->variables->getVariable($name);
     if (!$item) {
         $this->redirect(['index']);
     }
     if (isset($post['_csrf'])) {
         $model = KsconfigRecord::find()->where(['name' => $post['name']])->one();
         if ($model) {
             $model->data = $post['val'];
             $model->save();
             return $this->redirect(['update', 'name' => $model->name]);
         } else {
             if ($this->module->variables->getVariable($post['name'])) {
                 $model = new KsconfigRecord();
                 $model->name = $post['name'];
                 $model->data = $post['val'];
                 $model->save();
                 return $this->redirect(['update', 'name' => $model->name]);
             } else {
                 return $this->redirect(['index']);
             }
         }
     }
     return $this->render('update', ['item' => $item]);
 }
示例#2
0
 public function getVariables()
 {
     if (!$this->_keyValuesPairs) {
         $this->_keyValuesPairs = [];
         foreach ($this->config as $key => $item) {
             if (isset($item['default'])) {
                 $this->_keyValuesPairs[$key] = ['type' => $item['type'], 'value' => $item['default'], 'label' => $item['label'], 'values' => isset($item['values']) ? $item['values'] : false];
             } else {
                 $this->_keyValuesPairs[$key] = ['type' => $item['type'], 'value' => false, 'label' => $item['label'], 'values' => isset($item['values']) ? $item['values'] : false];
             }
         }
         $rows = KsconfigRecord::find()->all();
         if (count($rows) > 0) {
             foreach ($rows as $model) {
                 if (isset($this->_keyValuesPairs[$model->name])) {
                     $this->_keyValuesPairs[$model->name]['value'] = $model->data;
                 }
             }
         }
     }
     return $this->_keyValuesPairs;
 }