Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

[Solved] Limit output for a page

Go to End



Community Member, 15 Posts

21 May 2011 at 7:59am

Edited: 21/05/2011 8:48am

Hi all,

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);
return $songs;
This gets the current playlist songs, returns them and also limits them by a global limit setup through a custom site config.