Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Help with pagination in DataObject

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

Page: 1
Go to End
Author Topic: 1071 Views
  • Mauro74
    Avatar
    Community Member
    30 Posts

    Help with pagination in DataObject Link to this post

    Hi all,

    I'm pretty new to Silverstripe and PHP in general, so I'm learning by tutorials. In the well known website ssbits.com I found a very useful tutorial called 'DataObject as pages' (http://www.ssbits.com/tutorials/2010/dataobjects-as-pages-part-1-keeping-it-simple/). 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 GigPage_show.ss template
    function show()
    {
    if($GigDetail = $this->getGigDetail())
    {
    $Data = array(
    'GigDetail' => $GigDetail
    );

    //return our $Data array to use on the page
    return $this->Customise($Data);
    }
    else
    {
    //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">
    <h3>$Place</h3>
    <p>$Date.Nice - on stage at $Time</p>
    <p>Address: $Address</p>
    <p><a href="$Link">see map &raquo;</a></p>
    </div>
    <% end_control %>
    </div>
    <% end_if %>
    </div>

    Thanks in advance!

    Mauro

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Help with pagination in DataObject Link to this post

    Some pagination reference is available on http://doc.silverstripe.org/old/private:recipes:pagination

    1071 Views
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.