/** * Finds the Music model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Music the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Music::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionSave() { $thisUser = User::thisUser(); $id = Yii::$app->request->post('id'); $music = Music::findOne($id); if ($music->user_id == $thisUser->id) { $music->artist = Yii::$app->request->post('artist'); $music->title = Yii::$app->request->post('title'); $music->save(); } return json_encode(['musicHtml' => SoundWidget::widget(['music' => $music]), 'musicId' => $music->id]); }