Exemplo n.º 1
0
 /**
  * Creates a new Producto model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Producto();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 2
0
 /**
  * Creates a new Producto model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Producto();
     if ($model->load(Yii::$app->request->post())) {
         $foto = new UploadForm();
         $foto->imageFile = UploadedFile::getInstance($foto, 'imageFile');
         $upload_result = $foto->upload();
         if ($upload_result != false) {
             // file is uploaded successfully
             $model->Imagen = $upload_result;
             $model->save();
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     //Si no es post o el producto no se guarda correctamente se devuelve el formulario
     $img_model = new UploadForm();
     return $this->render('create', ['model' => $model, 'img_model' => $img_model]);
 }