/** * Creates a new SongKingdom model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new SongKingdom(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('songKingdomCreate', ['model' => $model]); } }
/** * 保存歌单 */ public function actionSave() { try { $post = Yii::$app->request->post(); $id = isset($post['song_kingdom_id']) ? $post['song_kingdom_id'] : ''; if (isset($_FILES['imageFile'])) { $resultUpload = $this->upload($_FILES['imageFile']); } if (!empty($id)) { $model = $this->findModel($id); } else { $model = new SongKingdom(); } if ($model->load($post)) { if (!empty($resultUpload)) { $model->cover = $resultUpload['cover']; $model->icon = $resultUpload['icon']; } if ($model->save()) { $result = ['statusCode' => '200', 'message' => '操作成功', 'navTabId' => 'music_song_kingdom_index_id', 'forwardUrl' => '', 'callbackType' => 'closeCurrent']; echo Json::encode($result); exit; } } $firstError = $model->getFirstError(); if (!empty($firstError)) { throw new \Exception($model->getFirstError()); } } catch (\Exception $exp) { $message = ''; $message .= $exp->getMessage(); $result = ['statusCode' => '300', 'message' => $message, 'navTabId' => 'music_song_kingdom_index_id', 'forwardUrl' => '', 'callbackType' => '']; echo Json::encode($result); exit; } }