7912 Posts in 1355 Topics by 930 members
|Go to End|
21 May 2011 at 7:59am Last edited: 21 May 2011 8:48am
I have made the following
Song -> DataObject
Playlist -> Holder of Songs
Now i want playlist to return xx amount of song and i need to control this from the playlist controller. So far i havent gotten anything working. I tried: $songs = DataObject::get('Song', '', '', '', $limit); wich ofcourse returns all songs. I cant figure out how to get songs from the page id. I tried ParentID = $this-id; but ofcourse that doesnt work. How do i get songs of the playlist page im on limited?
Solution is not to try and get parent id but PlaylistID. Ugh, feel so stupid for not getting this in the first place. Anyway here is the code in case anybody gets stuck with this ever again.
In the controller part of my playlist object wich holds many song classes, ive added:
function SongsLimit($defaultlimit = 20)
//Get Dataobject and set limit through globalsonglimit if available else use default limit
$global = SiteConfig::current_site_config();
$globallimit = $global->GlobalSongLimit;
$limit = ( $globallimit ) ? $globallimit : $defaultlimit;
$songs = DataObject::get("Song", "PlaylistID = $this->ID", "", "", $limit);
This gets the current playlist songs, returns them and also limits them by a global limit setup through a custom site config.
|Go to Top|