當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Artist::insertMultiple方法代碼示例

本文整理匯總了PHP中Artist::insertMultiple方法的典型用法代碼示例。如果您正苦於以下問題:PHP Artist::insertMultiple方法的具體用法?PHP Artist::insertMultiple怎麽用?PHP Artist::insertMultiple使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Artist的用法示例。


在下文中一共展示了Artist::insertMultiple方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: actionInject

 public function actionInject()
 {
     header('Content-type:application/json');
     $post = Yii::app()->getRequest()->getPost('chart');
     $weeks = $post['weeks'];
     $artists = array();
     $tracks = array();
     $chart_entries = array();
     // traverse $week
     /* weeks : [
      *  {
      *      week : 1,
      *      year : 2008,
      *      tracks : [{
      *          start : 0,
      *          mark : 1,
      *          position : 32,
      *          track : "Sexual Eruption",
      *          artist : "Snoop Dogg"
      *      }]
      *  }
      * ]
      */
     foreach ($weeks as $week) {
         foreach ($week['tracks'] as $chart_entry) {
             // populate artists
             $artist_name = $chart_entry['artist'];
             $artist_hash = md5($artist_name);
             if (!isset($artists[$artist_hash])) {
                 $artists[$artist_hash] = $artist_name;
             }
             // populate tracks
             $track_title = $chart_entry['track'];
             $track_hash = md5("{$track_title}\\%charty\\%{$artist_name}");
             if (!isset($tracks[$track_hash])) {
                 $tracks[$track_hash] = array('title' => $track_title, 'artist_hash' => $artist_hash);
             }
             // populate chart_entry_data
             $chart_entries[] = array('year' => $week['year'], 'week' => $week['week'], 'position' => $chart_entry['position'], 'track_hash' => $track_hash);
         }
     }
     $inserted_artists = Artist::insertMultiple($artists);
     $inserted_tracks = Track::insertMultiple($tracks);
     $inserted_chart_entries = ChartEntry::insertMultiple($chart_entries);
     echo json_encode(array('inserted_artists' => $inserted_artists, 'inserted_tracks' => $inserted_tracks, 'inserted_chart_entries' => $inserted_chart_entries));
 }
開發者ID:passport90,項目名稱:charty,代碼行數:46,代碼來源:FactoryController.php


注:本文中的Artist::insertMultiple方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。