Jump to:

7938 Posts in 1541 Topics by 945 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, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 864 Views
  • duskydesigns
    Community Member
    15 Posts

    [Solved] Limit output for a page Link to this post

    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.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.