Beispiel #1
0
 /**
  * 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();
     $model->scenario = 'create';
     if ($model->load(Yii::$app->request->post())) {
         // Force null
         $model->note = empty($model->note) ? null : $model->note;
         // Load metadata and get path from uploaded file
         $upload = UploadedFile::getInstance($model, 'meal_img_temp');
         if (!empty($upload)) {
             $previous = \backend\models\Meal::find()->select(['max(meal_id) as meal_id'])->one();
             $model->meal_id = $previous->meal_id + 1;
             $model->meal_img = 'upload/meal/' . $model->meal_id . '.' . $upload->extension;
             $model->meal_img_temp = true;
         }
         if ($upload->saveAs($model->meal_img) && $model->save()) {
             Yii::$app->getSession()->setFlash('meal_create_success', ['type' => Growl::TYPE_SUCCESS, 'title' => '<b>' . Yii::t('backend', 'Success') . '</b>', 'icon' => 'glyphicon glyphicon-ok-sign', 'body' => '<strong>' . $model->meal_text . '</strong> ' . Yii::t('backend', 'has been added.')]);
             return $this->redirect(['index']);
         } else {
             if ($upload->hasError) {
                 $error_msg = Yii::t('backend', 'Upload Falied.');
             } else {
                 $error_msg = Yii::t('backend', 'Failed to save data.');
             }
             Yii::$app->getSession()->setFlash('meal_create_failed', ['type' => \kartik\growl\Growl::TYPE_DANGER, 'title' => '<b>' . Yii::t('backend', 'Error') . '</b>', 'icon' => 'glyphicon glyphicon-remove-sign', 'body' => $error_msg]);
             return $this->render('create', ['model' => $model]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Beispiel #2
0
 /**
  * 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]);
     }
 }
Beispiel #3
0
 /**
  * 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]);
     }
 }