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 /

Help with pagination in DataObject


Reply


2 Posts   1116 Views

Avatar
Mauro74

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 ssbits.com I found a very useful tutorial called 'DataObject as pages' ([url]http://www.ssbits.com/tutorials/2010/dataobjects-as-pages-part-1-keeping-it-simple/[/url]). 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

Avatar
Willr

Forum Moderator, 5513 Posts

4 November 2011 at 6:25pm

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