예제 #1
0
 /**
  * Creates a new Option model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  *
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Option();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     }
     return $this->render('create', ['model' => $model]);
 }
예제 #2
0
 /**
  * Creates a new Option model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Option();
     $model->template_id = Yii::$app->request->get('template_id');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->getSession()->setFlash('option-create-success');
         return $this->redirect(['/template/update', 'id' => $model->template_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
예제 #3
0
 /**
  * Add new option, required name and value.
  * If value is array or object, it will be converted to json with Json::encode.
  *
  * @param string $name
  * @param string $value
  * @param string|array $label
  * @param string $group
  * @return bool
  */
 public static function set($name, $value, $label = null, $group = null)
 {
     if (is_array($value) || is_object($value)) {
         $value = Json::encode($value);
     }
     if (static::get($name) !== null) {
         return static::up($name, $value);
     }
     $model = new Option(['name' => $name, 'value' => $value, 'label' => $label, 'group' => $group]);
     return $model->save();
 }
예제 #4
0
파일: Option.php 프로젝트: tampaphp/app-cms
 /**
  * Add new option, required option_name and option_value.
  * If option_value is array or object, it will be converted to json with Json::encode.
  *
  * @param string       $optionName
  * @param string       $optionValue
  * @param string|array $optionLabel
  * @param string       $optionGroup
  *
  * @return bool
  */
 public static function set($optionName, $optionValue, $optionLabel = null, $optionGroup = null)
 {
     if (is_array($optionValue) || is_object($optionValue)) {
         $optionValue = Json::encode($optionValue);
     }
     if (static::get($optionName) !== null) {
         return static::up($optionName, $optionValue);
     }
     $model = new Option();
     $model->option_name = $optionName;
     $model->option_value = $optionValue;
     $model->option_label = $optionLabel;
     $model->option_group = $optionGroup;
     return $model->save();
 }
예제 #5
0
 /**
  * Add new option, required option_name and option_value.
  * If option_value is array or object, it will be converted to json with Json::encode.
  *
  * @param string       $option_name
  * @param string       $option_value
  * @param string|array $option_label
  * @param string       $option_group
  *
  * @return bool
  */
 public static function set($option_name, $option_value, $option_label = null, $option_group = null)
 {
     /* @var $model \common\models\Option */
     $model = new Option();
     if (is_array($option_value) || is_object($option_value)) {
         $model->option_value = Json::encode($option_value);
     } else {
         $model->option_value = $option_value;
     }
     $model->option_name = $option_name;
     $model->option_label = $option_label;
     $model->option_group = $option_group;
     return $model->save();
 }