/**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         //gets the instance of the uploaded file
         $ImageName = $model->name;
         $model->file = UploadedFile::getInstance($model, 'file');
         $model->file->saveAs('uploads/' . $ImageName . '.' . $model->file->extension);
         //saves db column path
         $model->logo = 'uploads/' . $ImageName . '.' . $model->file->extension;
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $imageName = $model->prod_id;
         $model->file = UploadedFile::getInstance($model, 'file');
         if ($model->validate() && $model->file) {
             $model->file->saveAs('uploads/' . $imageName . '.' . $model->file->extension);
             $model->prod_pic = 'uploads/' . $imageName . '.' . $model->file->extension;
             $model->save();
         }
         return $this->redirect(['view', 'id' => $model->prod_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     // $model->scenario = 'create';
     if ($model->load(Yii::$app->request->post())) {
         // if ($model->upload()) {
         //     $model->save();
         // }
         if (!$model->upload()) {
             // $model->addError('file', 'Необходимо добавить картинку.');
             return $this->render('create', ['model' => $model]);
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #5
0
 /**
  * function ::create ($data)
  */
 public static function create($data)
 {
     $now = strtotime('now');
     $username = Yii::$app->user->identity->username;
     $model = new Product();
     if ($model->load($data)) {
         if ($log = new UserLog()) {
             $log->username = $username;
             $log->action = "Create";
             $log->object_class = "Product";
             $log->created_at = $now;
             $log->is_success = 0;
             $log->save();
         }
         $model->created_at = $now;
         $model->created_by = $username;
         $model->published_at = strtotime($model->published_at);
         do {
             $path = FileUtils::generatePath($now);
         } while (file_exists(Yii::$app->params['images_folder'] . $path));
         $model->image_path = $path;
         $targetFolder = Yii::$app->params['images_folder'] . $model->image_path;
         $targetUrl = Yii::$app->params['images_url'] . $model->image_path;
         if (!empty($data['product-image'])) {
             $copyResult = FileUtils::copyImage(['imageName' => $model->image, 'fromFolder' => Yii::$app->params['uploads_folder'], 'toFolder' => $targetFolder, 'resize' => array_values(Product::$image_resizes), 'removeInputImage' => true]);
             if ($copyResult['success']) {
                 $model->image = $copyResult['imageName'];
             }
         }
         if (!empty($data['product-banner'])) {
             $copyResult = FileUtils::copyImage(['imageName' => $model->banner, 'fromFolder' => Yii::$app->params['uploads_folder'], 'toFolder' => $targetFolder, 'removeInputImage' => true]);
             if ($copyResult['success']) {
                 $model->banner = $copyResult['imageName'];
             }
         }
         if ($model->save()) {
             if ($log) {
                 $log->object_pk = $model->id;
                 $log->is_success = 1;
                 $log->save();
             }
             return $model;
         }
         $model->getErrors();
         return $model;
     }
     return false;
 }
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     $ProductCategoryRel = new ProductCategoryRel();
     if ($model->load(Yii::$app->request->post()) && $ProductCategoryRel->load(Yii::$app->request->post())) {
         if ($model->save()) {
             $ProductCategoryRel->product_id = $model->id;
             if ($ProductCategoryRel->category_id == '') {
                 $ProductCategoryRel->category_id = array(0);
             }
             if (Product::update_product_category_rel($ProductCategoryRel)) {
                 return $this->redirect(['view', 'id' => $model->id]);
             } else {
                 var_dump($ProductCategoryRel->getErrors());
             }
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             var_dump($model->getErrors());
         }
     } else {
         return $this->render('create', ['model' => $model, 'ProductCategoryRel' => $ProductCategoryRel]);
     }
 }