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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Working Pagination sample for ArticlesHilder from tutorial


Reply


3 Posts   1181 Views

Avatar
Nikolay

Community Member, 5 Posts

12 April 2011 at 11:19pm

http://doc.silverstripe.org/private:recipes:pagination
Empty

http://doc.silverstripe.org/sapphire/en/reference/dataobjectset
Not completed

Tutorial for AtricleHolder

Can some one write "recommended" and right code?

Avatar
Devlin

Community Member, 217 Posts

12 April 2011 at 11:29pm

Edited: 12/04/2011 11:43pm

Edit:
http://doc.silverstripe.org/old/private:recipes:pagination

function Articles($pagination=true) {
   if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
   $Limit = $pagination==true ? (int)$_GET['start'].",5" : null;

   $Articles = DataObject::get(
         'Articles',
         null,
         'Date DESC',
         null,
         $Limit
   );
   return !empty($Articles) ? $Articles : false;
}

And in the template...

<% if Articles.MoreThanOnePage %>
<p style="text-align:center;">
   <a href="$Articles.PrevLink" class="left"<% if Articles.PrevLink %><% else %> style="visibility:hidden;"<% end_if %>>&lt;&lt; Previous</a>
   <% control Articles.Pages %>
   <% if CurrentBool %>
   <strong>$PageNum</strong>
   <% else %>
   <a href="$Link" title="$PageNum">$PageNum</a>
   <% end_if %>
   <% end_control %>
   <a href="$Articles.NextLink" class="right"<% if Articles.NextLink %><% else %> style="visibility:hidden;"<% end_if %>>Next &gt;&gt;</a>
</p>
<% end_if %>

Avatar
Nikolay

Community Member, 5 Posts

13 April 2011 at 12:46am

Tnx Devlin.

I thought it would be more elegant:)