当前位置: 首页>>代码示例>>PHP>>正文


PHP Song::model方法代码示例

本文整理汇总了PHP中Song::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Song::model方法的具体用法?PHP Song::model怎么用?PHP Song::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Song的用法示例。


在下文中一共展示了Song::model方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionView

 public function actionView()
 {
     $this->layout = 'hopam_detail';
     $hopam = Song::model()->findByPk($_GET['id']);
     $hopam->view += 1;
     $hopam->update(array('view'));
     //$comment = $this->newComment($hopam);
     $cs = Yii::app()->getClientScript();
     $js = $this->generateJs();
     $cs->registerScript('sharebox', $js, CClientScript::POS_READY);
     $this->render('view', array('hopam' => $hopam));
     //,'comment'=>$comment
 }
开发者ID:ngdvan,项目名称:lntguitar,代码行数:13,代码来源:SongController.php

示例2: loadModel

 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Song::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
开发者ID:rainyjune,项目名称:YSMusic,代码行数:13,代码来源:SongController.php

示例3: actionEditmusic

 public function actionEditmusic($id)
 {
     $songModel = Song::model();
     $songModel = $songModel->findByPk($id);
     if (isset($_POST['Song'])) {
         $songModel->attributes = $_POST['Song'];
         if ($songModel->save()) {
             Yii::app()->user->setFlash('editmusicstatus', '修改音乐成功 :)');
         } else {
             Yii::app()->user->setFlash('editmusicstatus', '系统错误,修改失败 :(');
         }
     }
     $data = array('songModel' => $songModel);
     $this->render('editmusic', $data);
 }
开发者ID:returncn,项目名称:chen-xia-cms,代码行数:15,代码来源:AdminController.php

示例4: actionUpdate

 public function actionUpdate($id)
 {
     /* @var Artist $model */
     $model = $this->loadModel($id);
     // check access
     if (!Yii::app()->user->checkAccess('edit artist')) {
         throw new CHttpException(401);
     }
     // does this artists exists in our DB?
     if ($model === null) {
         Yii::log("Artist update requested with id {$id} but no such artist found!", CLogger::LEVEL_INFO, __METHOD__);
         throw new CHttpException(404, Yii::t("MusicModule.general", 'The requested page does not exist.'));
     }
     // enable adding songs by default (will be changed below if needed to)
     $enable_add_more_songs = true;
     if (isset($_POST['Artist'])) {
         // start optimistically
         $all_songs_valid = true;
         $songs_to_save = array();
         $success_saving_all = true;
         $model->attributes = $_POST['Artist'];
         if (isset($_POST['Song'])) {
             if (count($_POST['Song']) > Song::MAX_SONGS_PER_ARTIST) {
                 /*
                  * server side protection against attempt to submit more than MAX_SONGS_PER_ARTIST
                  * this should be accompanied with a client side (JS) protection.
                  * If its accompanied with client side protection then going into this code block means our system
                  * is being abused/"tested". No need to give a polite error message.
                  */
                 throw new CHttpException(500, Yii::t("MusicModule.forms", "The max amount of allowed songs is {max_songs_num}", array('{max_songs_num}' => Song::MAX_SONGS_PER_ARTIST)));
             }
             foreach ($_POST['Song'] as $index => $submitted_song) {
                 // We could have empty songs which means empty submitted forms in POST. Ignore those:
                 if ($submitted_song['title'] == '') {
                     // empty one - skip it, if you please.
                     continue;
                 }
                 // next, validate each submitted song instance
                 if ((int) $submitted_song['id'] > 0) {
                     /* Validate that the submitted song belong to this artist */
                     $song = Song::model()->findByPk($submitted_song['id']);
                     if ($song->artist->id != $model->id) {
                         Yii::log("Attempts to update Song with an id of {$song->id} but it belongs to an Artist with an id of {$song->model->id}" . " and not 'this' artist with id = {$model->id}", CLogger::LEVEL_ERROR, __METHOD__);
                         throw new CHttpException(500, "Error occurred");
                     }
                 } else {
                     // this submitted song object is a new model. instantiate one:
                     $song = new Song();
                 }
                 $song->attributes = $submitted_song;
                 if (!$song->validate()) {
                     // at least one invalid song:
                     $all_songs_valid = false;
                     // we do not 'break' here since we want validation on all song at the same shot
                 } else {
                     // put aside the valid song to be saved
                     $songs_to_save[] = $song;
                 }
             }
             // while we know that songs were submitted, determine if to show 'adding songs' or no.
             // a check whether the max songs per artist was exceeded was performed already above.
             if (count($_POST['Song']) == Song::MAX_SONGS_PER_ARTIST) {
                 $enable_add_more_songs = false;
             }
         }
         if ($all_songs_valid && $model->validate()) {
             /* all songs (if any) were valid and artist object is valid too. Save it all in one transaction. Save first the
              * artist as we need its id for its songs records
              */
             $trans = Yii::app()->db->beginTransaction();
             try {
                 // use aux variable for manipulating the image file.
                 $image = CUploadedFile::getInstance($model, 'icon_filename');
                 // check if a new image was submitted or not:
                 if ($image) {
                     /* the only thing that might have changed in the update is the extension name of the image (if you support more than 'only jpeg').
                      * therefore, if something was submitted, and since we already know the ID of the artist (this is an update scenario), we can
                      * determine the full updated icon_filename attribute of the model prior to its save() (unlike in create action - see there...).
                      */
                     $model->icon_filename = $model->getImageFsFilename($image);
                 }
                 $model->save(false);
                 // save the updated image, if any
                 if ($image) {
                     $image->saveAs($model->getImageFsFilename($image));
                 }
                 // save songs
                 foreach ($songs_to_save as $song) {
                     $song->save(false);
                 }
                 $trans->commit();
             } catch (Exception $e) {
                 // oops, saving artist or its songs failed. rollback, report us, and show the user an error.
                 $trans->rollback();
                 Yii::log("Error occurred while saving (update scenario) artist or its 'songs'. Rolling back... . Failure reason as reported in exception: " . $e->getMessage(), CLogger::LEVEL_ERROR, __METHOD__);
                 Yii::app()->user->setFlash('error', Yii::t("MusicModule.forms", "Error occurred"));
                 $success_saving_all = false;
             }
             if ($success_saving_all) {
                 $success_msg = count($songs_to_save) > 0 ? "Artist and song records have been updated" : "Artist record have been updated";
//.........这里部分代码省略.........
开发者ID:alejandrososa,项目名称:ventasYii,代码行数:101,代码来源:asd.php


注:本文中的Song::model方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。