Jump to:

23359 Posts in 18096 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Pagination AAARRGGHHH

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

Page: 1
Go to End
Author Topic: 239 Views
  • ambient
    Avatar
    Community Member
    123 Posts

    Pagination AAARRGGHHH Link to this post

    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

  • ambient
    Avatar
    Community Member
    123 Posts

    Re: Pagination AAARRGGHHH Link to this post

    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 %>

    239 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.