本文整理汇总了PHP中Option::setAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP Option::setAttributes方法的具体用法?PHP Option::setAttributes怎么用?PHP Option::setAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Option
的用法示例。
在下文中一共展示了Option::setAttributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
public function actionCreate()
{
$model = new Option();
$description = new OptionDescription();
$optionValue = new OptionValue();
$optionValueDes = new OptionValueDescription();
//$optionValueData = new CArrayDataProvider($this->_optionvalue);
$this->performAjaxValidation(array($model, $description, $optionValue), 'option-form');
if (isset($_POST[$this->modelName])) {
$model->setAttributes($_POST[$this->modelName]);
$description->setAttributes($_POST[$this->modelName . 'Description']);
//$optionValue->setAttributes($_POST['OptionValue']);
$suc = Yii::t('info', 'Option was successfully created');
$err = Yii::t('info', 'Could not update Option');
$errOpt = Yii::t('info', 'Please fill in the name and sort number for each option value');
$description->option_id = 0;
$description->locale_code = Yii::app()->getLanguage();
if ($model->validate() && $description->validate() && $this->validateOptionValue()) {
if ($model->save()) {
$description->option_id = $model->id;
$description->save();
foreach ($this->_optionvalue as $i => $optionvalue) {
$optionvalue->option_id = $model->id;
$optionvalue->save();
$this->_optionvaluedes[$i]->option_value_id = $optionvalue->id;
$this->_optionvaluedes[$i]->option_id = $model->id;
$this->_optionvaluedes[$i]->save();
}
Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, $suc);
if (Yii::app()->getRequest()->getIsAjaxRequest()) {
$this->renderPartial('_view', array('model' => $model, 'description' => $description, 'optionValue' => $this->_optionvalue, 'optionValueDes' => $this->_optionvaluedes, 'optionValueData' => new CArrayDataProvider($this->_optionvalue)), false, true);
Yii::app()->end();
} else {
$this->redirect(array('view', 'id' => $model->id));
}
} else {
Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, $err);
}
} else {
$description->validate();
if (!$this->validateOptionValue()) {
Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, $errOpt);
}
}
}
if (Yii::app()->getRequest()->getIsAjaxRequest()) {
$this->renderPartial('_form', array('model' => $model, 'description' => $description, 'optionValue' => $this->_optionvalue, 'optionValueDes' => $this->_optionvaluedes, 'optionValueData' => new CArrayDataProvider($this->_optionvalue)), false, true);
Yii::app()->end();
}
$this->render('create', array('model' => $model, 'description' => $description, 'optionValue' => $this->_optionvalue, 'optionValueDes' => $this->_optionvaluedes, 'optionValueData' => new CArrayDataProvider($this->_optionvalue)));
}
示例2: addOption
/**
* Adds an option given the config array.
* @param $config an array of config
*/
public function addOption(array $config)
{
$opt = new Option();
$opt->setAttributes($config);
$this->addChild($opt);
}