Beispiel #1
0
 public function actionUpdate($id)
 {
     if (!Yii::$app->user->can('product/update')) {
         Yii::$app->session->setFlash('error', 'Нет доступа!');
         return $this->redirect('/');
     }
     $categories = Product::loadCategory();
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Images::deleteImages($model);
         $upload = new UploadForm();
         $upload->imageFiles = UploadedFile::getInstances($model, 'images');
         if ($filename = $upload->upload('image_product/')) {
             Images::loadImages($upload, $filename, $model->id);
         }
         $model->sizeImages();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'categories' => $categories]);
     }
 }