7912 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » [Solved] Limit output for a page
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 688 Views |
-
[Solved] Limit output for a page

21 May 2011 at 7:59am Last edited: 21 May 2011 8:48am
Hi all,
I have made the following
Song -> DataObject
Playlist -> Holder of SongsNow 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.
| 688 Views | ||
|
Page:
1
|
Go to Top |

