public function actionBrandadd() { $model = new GoodsBrand(); if ($model->load(Yii::$app->request->post())) { //上传文章封面图 if ($_FILES['GoodsBrand']['name']['logo']) { $img = Yii::$app->imgload->UploadPhoto($model, 'uploads/brand/', 'logo'); $model->logo = $img; if ($model->save()) { Yii::$app->getSession()->setFlash('info', '添加成功!'); return $this->redirect(['brandlist']); } else { Yii::$app->getSession()->setFlash('info', '添加失败!'); @unlink($img); return $this->redirect(['brandlist']); } //不上传文章封面图 } else { if ($model->save()) { Yii::$app->getSession()->setFlash('info', '添加成功!'); return $this->redirect(['brandlist']); } } } return $this->render('brandadd', ['model' => $model]); }