コード例 #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Biobank('insert');
     if (isset($_POST['Biobank'])) {
         $attributesPost = $_POST['Biobank'];
         foreach ($attributesPost as $attName => $attValue) {
             if (!in_array($attName, $model->attributeNames())) {
                 $model->initSoftAttribute($attName);
             }
         }
         $model->attributes = $attributesPost;
         if (isset($_FILES['Logo'])) {
             $model->initSoftAttribute('activeLogo');
             $model->activeLogo = (string) $this->storeLogo($_FILES['Logo'], $model);
         }
         if (isset($_POST['Address'])) {
             $model->address = new Address('insert');
             $model->address = $_POST['Address'];
         }
         if ($model->save()) {
             $flashMsg = 'La biobanque a bien été créée.';
             if (!isset($model->contact_id) || $model->contact_id == "") {
                 $flashMsg .= '<br>Le contact n\'a pas été renseigné, n\'oubliez pas de le faire après sa création';
             }
             Yii::app()->user->setFlash('success', $flashMsg);
             $this->redirect(array('view', 'id' => $model->_id));
         } else {
             Yii::app()->user->setFlash('error', 'La biobanque n\'a pas pu être enregistrée');
         }
     }
     $this->render('create', array('model' => $model));
 }