Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Problem with pagination

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 2154 Views
  • OzziNL
    Avatar
    Community Member
    37 Posts

    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

  • OzziNL
    Avatar
    Community Member
    37 Posts

    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.

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