本文整理汇总了PHP中common\models\Option::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Option::save方法的具体用法?PHP Option::save怎么用?PHP Option::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common\models\Option
的用法示例。
在下文中一共展示了Option::save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* 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: actionCreate
/**
* 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: set
/**
* 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: set
/**
* 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: set
/**
* 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();
}