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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Help with Pagination


Go to End


3 Posts   851 Views

Avatar
SS SS

Community Member, 24 Posts

4 November 2011 at 7:02am

Edited: 04/11/2011 7:04am

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;
}

Avatar
Willr

Forum Moderator, 5523 Posts

4 November 2011 at 6:21pm

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

Avatar
SS SS

Community Member, 24 Posts

4 November 2011 at 10:41pm

Edited: 06/11/2011 10:52am

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

Sorted....