Example #1
0
 public function addData($id)
 {
     /* 处理上传的图片 */
     if ($_FILES['ArticleDownload']['error']['file_path'] === 0) {
         /* 把文件的路劲赋值给image字段 */
         $this->file_path = File::uploadImage($this, 'file_path', 'article');
     }
     if (!$this->id) {
         $this->id = $id;
     }
     return $this->save();
 }
Example #2
0
 /**
  * Updates an existing Brand model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     if (!$this->is_access('brand/update')) {
         Yii::$app->session->setFlash('error', $this->errorInfo);
         return $this->redirect($this->redirectUrl);
     }
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         /* 处理上传的图片 */
         if ($_FILES['Brand']['error']['brand_logo'] === 0) {
             /* 把文件的路劲赋值给image字段 */
             $model->brand_logo = File::uploadImage($model, 'brand_logo', 'other');
         }
         if ($model->save()) {
             Yii::$app->session->setFlash('success', '编辑成功');
         }
         return $this->redirect(['index']);
     } else {
         Yii::$app->view->params['meta_title'] = '编辑品牌';
         return $this->render('update', ['model' => $model]);
     }
 }
Example #3
0
 /**
  * Updates an existing FriendLink model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     if (!$this->is_access('links/update')) {
         Yii::$app->session->setFlash('error', $this->errorInfo);
         return $this->redirect($this->redirectUrl);
     }
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         /* 处理上传的图片 */
         if ($_FILES['FriendLink']['error']['link_logo'] === 0) {
             /* 把文件的路劲赋值给image字段 */
             $model->link_logo = File::uploadImage($model, 'link_logo', 'other');
         }
         if ($model->save()) {
             \backend\models\UserLog::addData('friend_link', $model->link_id, "编辑友情链接[{$model->link_name}]", 'edit');
             Yii::$app->session->setFlash('success', '编辑成功');
         }
         return $this->redirect(['index']);
     } else {
         Yii::$app->view->params['meta_title'] = '编辑链接';
         return $this->render('update', ['model' => $model]);
     }
 }
Example #4
0
 /**
  * Updates an existing Ad model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     if (!$this->is_access('ads/update')) {
         Yii::$app->session->setFlash('error', $this->errorInfo);
         return $this->redirect($this->redirectUrl);
     }
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         // 类型为 0:图片;1:Flash时
         if ($model->media_type == 0 || $model->media_type == 1) {
             /* 处理上传的图片 */
             if ($_FILES['Ad']['error']['ad_file'] === 0) {
                 /* 把文件的路劲赋值给image字段 */
                 $model->ad_code = File::uploadImage($model, 'ad_file', 'other');
             }
         }
         if ($model->save()) {
             Yii::$app->session->setFlash('success', '编辑成功');
         }
         return $this->redirect(['index']);
     } else {
         $AdPosition = new AdPosition();
         Yii::$app->view->params['meta_title'] = '编辑广告';
         $mediaList = $model->media_type_list();
         $position = $AdPosition->ad_position();
         return $this->render('update', ['model' => $model, 'mediaList' => $mediaList, 'position' => $position]);
     }
 }
Example #5
0
 /**
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     if (!$this->is_access('goods/update')) {
         Yii::$app->session->setFlash('error', $this->errorInfo);
         return $this->redirect($this->redirectUrl);
     }
     $model = $this->findModel($id);
     $GoodsGallery = new GoodsGallery();
     $post = Yii::$app->request->post();
     if ($model->load($post)) {
         $GoodsGallery->load($post);
         if ($model->validate() && $GoodsGallery->validate()) {
             // 商品封面图片
             if ($_FILES['Goods']['error']['goods_img'] === 0) {
                 $model->goods_img = File::uploadImage($model, 'goods_img', 'shop');
                 $model->goods_thumb = Images::thumb('./' . $model->goods_img, 250, 250);
             }
             if ($model->save(false)) {
                 // 商品相册
                 if ($_FILES['GoodsGallery']['error']['img_url'][0] === 0) {
                     $img_url = File::uploadImages($GoodsGallery, 'img_url', 'goods');
                     $GoodsGallery->addData($model->goods_id, $img_url);
                 }
                 // 商品属性
                 GoodsAttr::addData($model->goods_id);
             }
             Yii::$app->session->setFlash('success', '编辑成功');
         }
         return $this->redirect(['index']);
     } else {
         // 商品分类
         $Category = new Category();
         $categoryList = $Category->parent(0, false);
         // 品牌
         $Brand = new Brand();
         $brandList = $Brand->getLists();
         // 商品类型
         $GoodsType = new GoodsType();
         $goodsTypeList = $GoodsType->dropList();
         // 相册
         $goodsGalleryList = $GoodsGallery->getGoodsGallery($id);
         Yii::$app->view->params['meta_title'] = '编辑商品';
         return $this->render('update', ['model' => $model, 'GoodsGallery' => $GoodsGallery, 'categoryList' => $categoryList, 'brandList' => $brandList, 'goodsTypeList' => $goodsTypeList, 'goodsGalleryList' => $goodsGalleryList]);
     }
 }