示例#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]);
     }
 }
示例#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]);
 }
 /**
  * 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();
     $categoria = new Categoria();
     $categoriasActivas = $categoria->getCategoriasActivas();
     if ($model->load(Yii::$app->request->post())) {
         $nombreImagen = $model->nombre;
         $model->file = UploadedFile::getInstance($model, 'file');
         $model->imagen = 'img/' . $nombreImagen . '.' . $model->file->extension;
         if ($model->validate()) {
             $model->save();
             $model->file->saveAs('img/' . $model->nombre . '.' . $model->file->extension);
             Yii::$app->getSession()->setFlash('success', Yii::t('core', 'Product has been succesfully created'));
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model, 'categorias' => $categoriasActivas]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'categorias' => $categoriasActivas]);
     }
 }