示例#1
0
 public function actionBrandedit()
 {
     if (Yii::$app->request->get('id')) {
         $id = Yii::$app->request->get('id');
         $model = GoodsBrand::findOne($id);
         return $this->render('brandedit', ['id' => $id, 'model' => $model]);
     } elseif (Yii::$app->request->post('id')) {
         $id = Yii::$app->request->post('id');
         $model = GoodsBrand::findOne($id);
         $logo = $model->logo;
         if ($model === null) {
             Yii::$app->getSession()->setFlash("info", '编辑失败');
             return $this->redirect(['brandlist']);
         }
         if ($model->load(Yii::$app->request->post())) {
             if ($_FILES['GoodsBrand']['name']['logo']) {
                 //删除原图片
                 if ($logo) {
                     unlink($logo);
                 }
                 //更新新图片
                 $img = Yii::$app->imgload->UploadPhoto($model, 'uploads/brand/', 'logo');
                 $model->logo = $img;
             } else {
                 $model->logo = $logo;
             }
             if ($model->save()) {
                 Yii::$app->getSession()->setFlash('info', '编辑成功!');
                 return $this->redirect(['brandlist']);
             } else {
                 Yii::$app->getSession()->setFlash('info', '编辑失败!');
                 @unlink($img);
                 return $this->redirect(['brandlist']);
             }
         }
     }
 }
示例#2
0
 public function actionGoodsadd()
 {
     //获取商品类型及其属性
     $type = GoodsType::find()->all();
     //获取商品分类信息
     $category = new GoodsCategory();
     $cate = $category->list_cate();
     //获取商品品牌信息
     $brand = GoodsBrand::find()->all();
     $model = new Goods();
     return $this->render('goodsadd', ['type' => $type, 'cate' => $cate, 'brand' => $brand, 'model' => $model]);
 }