/** * Creates a new Sanpham model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Sanpham(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id_sanpham]); } else { return $this->renderAjax('create', ['model' => $model]); } }
/** * Creates a new Sanpham model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Sanpham(); $list = Loaisanpham::find()->all(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect('index.php?r=sanpham%2Findex'); } else { return $this->render('create', ['model' => $model, 'list' => $list]); } }
public function actionCreate() { $lstLine = Loaisanpham::find()->where(['between', 'status', 1, 4])->all(); $model = new Sanpham(); if ($model->load(Yii::$app->request->post())) { if ($model->validate()) { $model->status = 1; $model->save(); $model->file = UploadedFile::getInstance($model, 'file'); if ($model->file) { $id = $model->id_sp; $imageName = "loaisanpham_" . $id . '_' . getdate()[0]; $model->file->saveAs('uploads/' . $imageName . '.' . $model->file->extension); $station = Sanpham::findOne($id); $station->sp_anh = '@web/uploads/' . $imageName . '.' . $model->file->extension; $station->save(); } return $this->redirect(['sanpham/index']); } } else { return $this->render('create', ['user' => $model, 'listLine' => $lstLine]); } }