/** * Creates a new Meal model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Meal(); 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 Meal model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Meal(); $productImages = new MealImage(); $data = []; $getItems = MealItem::find()->all(); foreach ($getItems as $key => $value) { $data[$value->id] = $value->name; } //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())) { $dateTime = $model->deal_closing_time; //$model->day = $model->day; $model->deal_closing_time = strtotime($dateTime); $model->created_at = time(); //$model->deal_status; if ($model->save()) { $productImages->meal_id = $model->id; // upload image by this method $this->uploadImage($productImages); $mealItems = Yii::$app->request->post('meal_id'); if (!empty($mealItems)) { foreach ($mealItems as $key => $itemID) { $mealItemsManage = new MealItemsManage(); $mealItemsManage->meal_id = $model->id; $mealItemsManage->item_id = $itemID; $mealItemsManage->created_at = time(); if ($mealItemsManage->save()) { } } } return $this->redirect(['view', 'id' => $model->id]); } } else { return $this->render('create', ['model' => $model, 'productImages' => $productImages, 'data' => $data]); } }