/** * Creates a new MealItem model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new MealItem(); $model->created_at = date('Y-m-d h:i:s'); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new MealItem model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new MealItem(); $model->created_at = date('Y-m-d h:i:s'); $productImages = new MealItemImage(); //Yii::$app->params['uploadPath'] = Yii::$app->basePath . '/uploads/'; //below code is where you will do your own stuff. This is just a sample code need to do work on saving files if ($model->load(Yii::$app->request->post()) && $model->save()) { $productImages->itemId = $model->id; // upload image by this method $this->uploadImage($productImages); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'productImages' => $productImages]); } }