本文整理汇总了PHP中FormField::save方法的典型用法代码示例。如果您正苦于以下问题:PHP FormField::save方法的具体用法?PHP FormField::save怎么用?PHP FormField::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormField
的用法示例。
在下文中一共展示了FormField::save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionNew
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionNew()
{
if (isset($_GET['form'])) {
$form_id = $_GET['form'];
$model = new FormField();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['FormField'])) {
$model->attributes = $_POST['FormField'];
$model->VARNAME = str_replace(' ', '_', $model->TITLE);
$model->VARNAME = strtoupper($model->VARNAME);
$model->FORM_ID = $form_id;
//if($model->save())
// $this->redirect(array('view','field'=>$model->FIELD_ID));
$form = Form::model()->findByPk($form_id);
if ($model->FIELD_TYPE == 'DATE') {
$column_t = 'TIMESTAMP ';
$column_t .= 'DEFAULT "0000-00-00 00:00:00"';
} elseif ($model->FIELD_TYPE == 'INTEGER') {
//$column_t='INT('.$model->FIELD_SIZE.') NOT NULL DEFAULT'.($model->DEFAULT)?$model->DEFAULT:$model->DEFAULT;
$column_t = 'INT(' . $model->FIELD_SIZE . ') ';
if (is_int($model->DEFAULT)) {
$column_t .= 'DEFAULT ' . $model->DEFAULT;
} else {
$model->DEFAULT = '';
}
} elseif ($model->FIELD_TYPE == 'VARCHAR') {
$column_t = 'VARCHAR(' . $model->FIELD_SIZE . ') ';
if ($model->DEFAULT) {
$column_t .= 'DEFAULT ' . $model->DEFAULT;
} else {
$model->DEFAULT = '';
}
} else {
$column_t = $model->FIELD_TYPE . ' ';
if ($model->DEFAULT) {
$column_t .= 'DEFAULT ' . $model->DEFAULT;
} else {
$model->DEFAULT = '';
}
}
if (!FormField::model()->findAllByAttributes(array('VARNAME' => $model->VARNAME, 'FORM_ID' => $form_id))) {
if ($model->save()) {
Yii::app()->db->createCommand()->addColumn($form->TABLE_NAME, $model->VARNAME, $column_t);
$this->redirect(array('fields/index', 'form' => $model->FORM_ID));
}
} else {
$model->addError('VARNAME', 'Column "' . $model->VARNAME . '" already exists. Please pick a new column name.');
}
}
$this->render('new', array('model' => $model, 'form_id' => $form_id));
} else {
throw new CHttpException(404, 'The requested page does not exist.');
}
}
示例2: updateFormFields
/**
* Actualiza los campos del formulario
* @param $fieldsConfig
*/
public function updateFormFields($fieldsConfig)
{
DB::beginTransaction();
try {
$this->fields()->delete();
foreach ($fieldsConfig as $fieldConfig) {
$field = new FormField();
$field->form_id = $this->id;
$field->name = array_get($fieldConfig, 'name', '');
$field->alias = array_get($fieldConfig, 'alias', '');
$field->type = array_get($fieldConfig, 'type.type', '');
$field->config = array_get($fieldConfig, 'config', null);
$field->save();
}
} catch (\Exception $e) {
DB::rollBack();
Log::error($e->getMessage());
}
DB::commit();
}