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.

Data Model Questions /

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

Help with pagination in DataObject

Go to End

2 Posts   1441 Views


Community Member, 30 Posts

4 November 2011 at 12:08am

Hi all,

I'm pretty new to Silverstripe and PHP in general, so I'm learning by tutorials. In the well known website I found a very useful tutorial called 'DataObject as pages' ( The tutorial is great, it shows how to create a list of staff members without using pages and using the DataObjectManager in the CMS.

I used the tutorial to implement a list of events, but now I'm stuck finding a way to paginate the list! Anyone could help me please?
here's my controller:

class GigPage_Controller extends Page_Controller
    //Allow our 'show' function as a URL action
    static $allowed_actions = array('show');
    //Get the current gig detail from the URL, if any
    public function getGigDetail()
        $Params = $this->getURLParams();
        if(is_numeric($Params['ID']) && $GigDetail = DataObject::get_by_id('GigDetail', (int)$Params['ID']))
            return $GigDetail;
    //Displays the gig detail detail page, using template
    function show()
        if($GigDetail = $this->getGigDetail())
            $Data = array(
                'GigDetail' => $GigDetail
            //return our $Data array to use on the page
            return $this->Customise($Data);
            //Gig not found
            return $this->httpError(404, 'Sorry that member of staff could not be found');
    //Return our custom breadcrumbs
    public function Breadcrumbs() {
        //Get the default breadcrumbs
        $Breadcrumbs = parent::Breadcrumbs();
        if($GigDetail = $this->getGigDetail())
            //Explode them into their individual parts
            $Parts = explode(SiteTree::$breadcrumbs_delimiter, $Breadcrumbs);
            //Count the parts
            $NumOfParts = count($Parts);
            //Change the last item to a link instead of just text
            $Parts[$NumOfParts-1] = ('<a href="' . $this->Link() . '">' . $Parts[$NumOfParts-1] . '</a>');
            //Add our extra piece on the end
            $Parts[$NumOfParts] = $GigDetail->Place .' - '. $GigDetail->Date;
            //Return the imploded array
            $Breadcrumbs = implode(SiteTree::$breadcrumbs_delimiter, $Parts);          
        return $Breadcrumbs;

here's my template:

<div class="typography">
  <% if GigDetails %>
    <div id="gig-list">
        <% control GigDetails %>
        <div class="gig">
            <p>$Date.Nice - on stage at $Time</p>
            <p>Address: $Address</p>
            <p><a href="$Link">see map &raquo;</a></p>
        <% end_control %>
    <% end_if %>

Thanks in advance!



Forum Moderator, 5523 Posts

4 November 2011 at 6:25pm

Some pagination reference is available on