Remember me? forgot password | register

SilverStripe Forum

10688 Posts in 2795 Topics by 1518 members

Jump to:

Site Builders

If this is your first visit, you will need to register before you can post. However, you can browse all messages below.

Community » SilverStripe Forum » Site Builders » Problem with pagination
Page: 1 go to end Reply
Author Topic: Problem with pagination 650 views
  • OzziNL
    avatar
    Community Member
    24 posts
    5 SilverStripe Sites

    Problem with pagination Link to this post

    Hello, I am trying to solve a problem with pagination for two days now! I'll explain:


    //on a controller
       function showActivities() {
          
          isset($_GET['start']) ? $start = $_GET['start'] : $start = 0;
          
          $list = DataObject::get("ActiviteitPage", "","", "","{$start}," . AANTAL_ITEMS_ACTIVITEITENOVERZICHT );
             
          return ($list) ? $list : null;
       }

    On the template:


           <!-- pagination -->
              <% if showActivities.MoreThanOnePage %>
               <div id="head_itc_file">
               <% control showActivities.Pages %>
                  <% if CurrentBool %>
                     <img src="/themes/inventheon/images/file_itc.gif" alt="" />
                  <% else %>
                     <a href="$Link"><img src="/themes/inventheon/images/file_off_itc.gif" alt="" /></a>
                  <% end_if %>
               <% end_control %>
               </div>
              <% end_if %>
           <!-- end pagination -->
    //...cut
    $ActiviteitenLijst.Count //PRINTS 3
    <% include ActiviteitenLijst %> //PRINTS 3 ITEMS

    Now the problem: The pagination returns pages for 107 items. Whatever the numer of items per page, it is based on 107 item (1 -> 107 pages, 10 -> 11 pages )

    looking in the code I see the problem comes from:


    $this->setPageLimits($start, $length, $query->unlimitedRowCount());

    The last parameter is 107 and should be 5 (there are 5 ActiviteitPage items)

    Now: it gets odd:

    in this code in SQLQuery.php:


       function unlimitedRowCount( $column = "*" ) {
          $clone = clone $this;
          $clone->select = array("count($column)");
          $clone->limit = null;
          $clone->orderby = null;
          $clone->groupby = null;
          Debug::show($clone); // THIS DUMP LINE!!!!!!!!!!!!!!!!!!!!!!!!!!!
          $queryContent = singleton('SiteTree')->extendedSQL();
          return $queryContent->execute()->value();
       }

    The dump line prints:

    SQLQuery::__set_state(array( 'select' => array ( 0 => 'count(*)', ), 'from' => array ( 'SiteTree' => '`SiteTree_Live`', 'InventheonPage' => 'LEFT JOIN `InventheonPage_Live` ON `InventheonPage_Live`.ID = `SiteTree_Live`.ID', 'ActiviteitPage' => 'LEFT JOIN `ActiviteitPage_Live` ON `ActiviteitPage_Live`.ID = `SiteTree_Live`.ID', ), 'where' => array ( 0 => '`SiteTree_Live`.ClassName IN (\'ActiviteitPage\')', ), 'orderby' => NULL, 'groupby' => NULL, 'having' => NULL, 'limit' => NULL, 'distinct' => NULL, 'delete' => NULL, 'extension_instances' => array ( ), 'class' => 'SQLQuery', ))

    I translate it myself to sql and that is:

    SELECT count(*)
    FROM SiteTree_Live
    LEFT JOIN `InventheonPage_Live` ON `InventheonPage_Live`.ID = `SiteTree_Live`.ID
    LEFT JOIN `ActiviteitPage_Live` ON `ActiviteitPage_Live`.ID = `SiteTree_Live`.ID
    WHERE `SiteTree_Live`.ClassName IN ('ActiviteitPage')

    And when I run it: 5 !!!!!!

    But the function SQLQuery::unlimitedRowCount() returns 107

    Please any help!!!
    I don't understand this anymore...

    Thanks,
    Oscar

    Last edited: 16 April 2008 at 9:11am

  • OzziNL
    avatar
    Community Member
    24 posts
    5 SilverStripe Sites

    Re: Problem with pagination Link to this post

    Case closed!
    Don't know how this code became as pasted but this function is not like the function in the Stable.

    650 views
go to top Reply

Currently Online:

Harl

Welcome to our latest member: lorem