Exemple #1
0
 /**
  * Creates a new Song model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Song();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('songCreate', ['model' => $model]);
     }
 }
Exemple #2
0
 /**
  * 保存创建和修改的信息
  */
 public function actionSave()
 {
     try {
         $post = Yii::$app->request->post();
         $id = isset($post['song_id']) ? $post['song_id'] : '';
         $post['Song']['song_kingdom_id'] = !empty($post['songKingdom_id']) ? $post['songKingdom_id'] : '';
         if (!empty($id)) {
             $model = $this->findModel($id);
             if ($model->load($post) && $model->save()) {
                 $song_id = $id;
             }
         } else {
             $model = new Song();
             if ($model->load($post) && $model->save()) {
                 $song_id = Yii::$app->db->getLastInsertID();
             }
         }
         if (empty($song_id)) {
             throw new \Exception('写入歌曲失败');
         }
     } catch (\Exception $exp) {
         $result = ['statusCode' => '300', 'message' => $exp->getMessage(), 'navTabId' => 'music_song_index_id', 'forwardUrl' => '', 'callbackType' => ''];
         echo Json::encode($result);
         exit;
     }
     $result = ['statusCode' => '200', 'message' => '操作成功', 'navTabId' => 'music_song_index_id', 'forwardUrl' => '', 'callbackType' => 'closeCurrent'];
     echo Json::encode($result);
     exit;
 }