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

Pagination issue 2.4


Reply

221 Views

Avatar
Judderman

17 September 2013 at 8:14pm Community Member, 1 Post

Hi

I'm Editing one of my older 2.4 sites as the client has requested the jquery pagination needs to be a physical one which i added to the Category page yesterday, this was working initially but has since stopped giving me any results. I cant fault the code or find any reason why in the instance of the pagination function its no longer giving any results?

The first function retrieves all the products to this category, this works but when i reference the function or replicate the process in pagination it doesn't return any results or errors?

//Return the list of products for this category
   public function getProductsList(){
      return $this->Products(Null, 'Title ASC');
   }
   
   //Return the list of products using pagination
   function getChildPages() {
      if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
         $SQL_start = (int)$_GET['start'];
         $listedProducts = $this->getProductsList();
         $doSet = new DataObjectSet();
         foreach ($listedProducts as $listedProduct) {
            if ($listedProduct->canView()) {
               $doSet->push($listedProduct);
            }
         }
      $doSet->setPageLimits($SQL_start, 12, $doSet->Count());
   return $doSet;
   }

In the page we have:

<div class="product_navigation">
<% if getChildPages.MoreThanOnePage %><p><% if getChildPages.PrevLink %><a href="$getChildPages.PrevLink">&lt; Prev</a> | <% end_if %><% control getChildPages.Pages %><% if CurrentBool %><strong> $PageNum </strong><% else %><a href="$Link" title="Go to page $PageNum">$PageNum</a><% end_if %><% end_control %><% if getChildPages.NextLink %> | <a href="$getChildPages.NextLink">Next &gt;</a><% end_if %></p><% end_if %>
</div>
<div class="products">
   <% control getChildPages.Pagination %>
   <div class="box">
      <a href="$Link" title="$Title">
      <div class="img_holder">
      <% if MainImage %>
         $MainImage.CroppedImage(125,90)
    <% else %>
         <img src="$ThemeDir/images/comingsoon.jpg" alt="Image coming soon" />
      <% end_if %>
      </div>
      <h1>$Year $Make<br/>$Model</h1>
      <p>more information &raquo;</p>
      </a>
   </div>
<% end_control %>
</div>   

Any help would be welcomed