本文整理汇总了PHP中Playlist::populate方法的典型用法代码示例。如果您正苦于以下问题:PHP Playlist::populate方法的具体用法?PHP Playlist::populate怎么用?PHP Playlist::populate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Playlist
的用法示例。
在下文中一共展示了Playlist::populate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: foreach
//indicate the requester is not the playlist owner and is not allowed to update it
return;
}
//get request's body containing array of track's id
if (!array_key_exists('body', $api->query)) {
$api->output(400, 'Track identifiers must be provided in request body');
//tracks identifier were not provided, return an error
return;
}
$tracks = $api->query['body'];
if (!is_array($tracks)) {
$api->output(400, 'Track identifiers must be provided in an array');
//tracks identifier were not provided, return an error
return;
}
//add each tracks
foreach ($tracks as $track) {
$playlistItem = new PlaylistItem($userId, null, $track->id);
$playlistItem->insert();
}
//get full user's playlist for response
$playlist = new Playlist($userId);
$playlist->populate();
if (count($playlist->tracks) === 0) {
$api->output(204, null);
//user's playlist is empty
return;
}
$api->output(200, $playlist->tracks);
break;
}