/** * Creates a new FriendLink model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (!$this->is_access('links/create')) { Yii::$app->session->setFlash('error', $this->errorInfo); return $this->redirect($this->redirectUrl); } $model = new FriendLink(); 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}]", 'add'); Yii::$app->session->setFlash('success', '新增成功'); } return $this->redirect(['index']); } else { Yii::$app->view->params['meta_title'] = '添加新链接'; return $this->render('create', ['model' => $model]); } }