コード例 #1
0
ファイル: MainController.php プロジェクト: barricade86/raui
 public function actionCreate()
 {
     $model = new FormDesigner();
     $model->scenario = 'advanced';
     $model->type = FormDesigner::TYPE_TEXT;
     $translate = new TranslateMessage();
     if (isset($_POST['FormDesigner'])) {
         $model->attributes = $_POST['FormDesigner'];
         if ($model->validate()) {
             // magic begin
             $this->fieldName = translit($model->getStrByLang('label'), '_', true);
             $this->fieldName = substr($this->fieldName, 0, 12);
             if ($this->setFieldInTable($_POST['FormDesigner']['type'])) {
                 $model->field = $this->fieldName;
                 $translate->attributes = $_POST['TranslateMessage'];
                 $translate->category = 'common';
                 $translate->message = 'Search by ' . $this->fieldName;
                 if ($translate->save()) {
                     $model->save();
                     Yii::app()->cache->flush();
                     Yii::app()->user->setFlash('success', tt('The new field is successfully created.'));
                     $this->redirect(Yii::app()->createUrl('/formdesigner/backend/main/admin'));
                 }
             } else {
                 $model->addError('', tt('Failed to create field'));
             }
         }
     }
     $this->render('create', array('model' => $model, 'translate' => $translate));
 }