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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

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

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

Pagination AAARRGGHHH


Go to End


2 Posts   585 Views

Avatar
ambient

Community Member, 130 Posts

25 November 2013 at 10:07am

Hi All,
I've been at this for ages, I know there seems to be a lot out there about the pagination of DataObjects but for the life of me I can't figure out what I'm doing wrong!?!?
All the DataObjects show up on the page when only 6 should. Also the 1 2 | Next >> also shows up but has no effect.

ArticleItem.php is my DataObject

So in my ArticleHolder.php Controller I have:

class ArticlePage_Controller extends Page_Controller {
	
	function ArticleItem() {
		if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) 
		{
			$_GET['start'] = 0;
		}

		$SQL_start = (int)$_GET['start'];
	
		$newsEntries = DataObject::get('ArticleItems', '', 'Date DESC');
		$doSet = new DataObjectSet();
			foreach ($newsEntries as $newsEntry) {
				if ($newsEntry->canView()) {
					$doSet->push($newsEntry);
				}
			}
		$doSet->setPageLimits($SQL_start, 10, $doSet->Count());
    return $doSet;
}
	
}

And then in my ArticleHolder.ss I have:

<% control ArticleItems %>
<div class="article">
  <h2>$ArticleTitle</h2>
  <% if ArticleDesc %>
  $ArticleDesc
  <% end_if %>
  <a href="$ArticleUrl.Link" target="_blank">Read More...</a>
</div>
<% end_control %>

<% if ArticleItems.MoreThanOnePage %>

	<% if ArticleItems.PrevLink %>
    <a href="$ArticleItems.PrevLink">&lt;&;lt; Prev</a> |
	<% end_if %>

	<% control ArticleItems.Pages %>
        <% if CurrentBool %>
        <strong>$PageNum</strong>
        <% else %>
        <a href="$Link" title="Go to page $PageNum">$PageNum</a>
        <% end_if %>
    <% end_control %>

	<% if ArticleItems.NextLink %>
    | <a href="$ArticleItems.NextLink">Next &gt;&gt;</a>
    <% end_if %>
    
<% end_if %>

All and any help is appreciated :)

Avatar
ambient

Community Member, 130 Posts

26 November 2013 at 5:54am

Edited: 26/11/2013 5:56am

I somehow got it working :)
I think it was because I didn't initially have a 'Date' field.... I think....

And then this for my ArticlePage.ss

<% if AllNewsPosts %>
    <% control AllNewsPosts.Pagination %>
    <div class="article">
      <h3>$ArticleTitle</h3>
      <% if ArticleDesc %>
      $ArticleDesc
      <% end_if %>
      <a href="$ArticleUrl.Link" target="_blank">Read More...</a> </div>
    <% end_control %>
    <% else %>
    <div class="no-entry">'There are no entries'</div>
    <% end_if %>
    
    <% if AllNewsPosts.MoreThanOnePage %>
    <div class="pagination" style="float:right;">
      <p>
        <% if AllNewsPosts.NotFirstPage %>
        <a class="prev" href="$AllNewsPosts.PrevLink" title="View the previous page">&lt; Prev</a>
        <% end_if %>
        <span>
        <% control AllNewsPosts.PaginationSummary(0) %>
        <% if CurrentBool %>
        <span class="current">$PageNum</span>
        <% else %>
        <% if Link %>
        <a href="$Link" class="numbers" title="View page number $PageNum">$PageNum</a>
        <% else %>
        &hellip;
        <% end_if %>
        <% end_if %>
        <% end_control %>
        </span>
        <% if AllNewsPosts.NotLastPage %>
        <a class="next" href="$AllNewsPosts.NextLink" title="View the next page">Next &gt;</a>
        <% end_if %>
      </p>
    </div>
    <% end_if %>