/** * Creates a new Categorias model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Categorias(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->idcategoria]); } else { return $this->render('create', ['model' => $model]); } }
public function crear() { $model = new Categorias(); $image = $this->cargarImagen(); if ($this->validate()) { $model->nombre = ucfirst($this->nombre); $model->estado = $this->estado; $model->descripcion = ucfirst($this->descripcion); $model->icono = $this->icono; if ($model->save()) { if (!empty($image)) { // the path to save file, you can set an uploadPath $path = Yii::getAlias('@libreria') . '/imagenes/categorias/' . $this->icono; $image->saveAs($path); Yii::$app->session->setFlash('error', ['Error 1', 'Error 2']); } return true; } else { return false; } } return false; }