Jump to:

23481 Posts in 18951 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Help with Pagination

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: 556 Views
  • ss-ss
    Avatar
    Community Member
    15 Posts

    Help with Pagination Link to this post

    Wrote a function below to search the products (custom search). It is returning me all the valid records.... No problems at all. Want to introduce pagination. Would somebody help please.

    function ProductSearch() {
       global $databaseConfig;
       $query = new SQLQuery();
       $query->select = array(
          "Title",
          "Content",
          "URLSegment"
       );
       $query->from("xx_xxx");
       $query->where("ShowInSearch = 1 AND ClassName = 'Product' AND Title LIKE '%" . mysql_real_escape_string($srchProduct)");
       $query->orderby("Title ASC, ID ASC");
       $result = $query->execute();
       $plist = new DataObjectSet();
       foreach($result as $DataRow) {
          $plist->push(new ArrayData($DataRow));
       }

       } else {
          $plist = NULL;
       }
       return $plist;
    }

  • Willr
    Avatar
    Forum Moderator
    5503 Posts

    Re: Help with Pagination Link to this post

    If you have a DataObjectSet then pagination functions are built it. You can see an example of it - http://doc.silverstripe.org/old/private:recipes:pagination

  • ss-ss
    Avatar
    Community Member
    15 Posts

    Re: Help with Pagination Link to this post

    Thanks Willr, Looked at SS code to know the syntax.. Used DataObject with filter....

    Sorted....

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