/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new SystemSetting();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['SystemSetting'])) {
         //var_dump($_POST['SystemSetting']); exit();
         $model->attributes = $_POST['SystemSetting'];
         if ($model->save()) {
             Yii::app()->user->setFlash('success', "Tạo mới thành công <b>{$model->code}</b>");
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Exemplo n.º 2
0
 protected function save($settings)
 {
     $result = true;
     foreach ($settings as $key => $value) {
         $item = SystemSetting::model()->findByAttributes(array('name' => $key));
         if (!$item) {
             $item = new SystemSetting();
             $item->name = $key;
         }
         $item->value = json_encode($value);
         if (!$item->save()) {
             $result = false;
         }
     }
     if (($cache = Yii::app()->cache) !== null) {
         $cache->delete($this->_key);
     }
     return $result;
 }