Esempio n. 1
0
 /**
  * Creates a new Pair model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Pair();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Esempio n. 2
0
 public function set($name, $value, $jsonEncode = false)
 {
     $encoded = false;
     //force array to be json
     if (is_array($value)) {
         $value = Json::encode($value);
         $encoded = true;
     }
     //encode only non-empty value
     if (!$encoded && $jsonEncode && $value !== "") {
         $value = Json::encode($value);
     }
     $model = new Pair();
     $model->name = $name;
     $model->value = $value;
     try {
         $model->save();
         return Yii::$app->db->getLastInsertID();
     } catch (ErrorException $e) {
         Yii::warning(Yii::t('app', 'Not saved!'));
         return false;
     }
 }