Simple example of how to use the pagination api?
Permalink 1 user found helpful
Does anyone have a simple example of how to use the pagination api?
I'm querying a db table and would like to spread the result over multiple pages.
Thanks!
I'm querying a db table and would like to spread the result over multiple pages.
Thanks!
A basic example:
Hi beebs93,
Thanks for your example but I'm still very confused. Is the pagination helper built to work with pages only?
what I need is as follows:
I have a table with a 30 items, I would like to query the database and return 10 items per page with "next" and "previous" links.
In Drupal I was able to do that with the pagination class.
Thanks!
Thanks for your example but I'm still very confused. Is the pagination helper built to work with pages only?
what I need is as follows:
I have a table with a 30 items, I would like to query the database and return 10 items per page with "next" and "previous" links.
In Drupal I was able to do that with the pagination class.
Thanks!
I've only ever used the pagination class for pages. What kind of items are you retrieving from the C5 database?
I have create a table of paintings, I use a web service (SOAP) to update the table.
fields: (id)(title)(artists)(date_added)
fields: (id)(title)(artists)(date_added)
I'll start poking around the related libraries, but I think one of the more experienced C5 developers would have a better understanding.
I'll post anything useful I come across :)
I'll post anything useful I come across :)
No, you can also use that for things besides pages (pages is just the most common use case in the c5 world). The PageList class builds off of a lower-level class called "DatabaseItemList", which you can also use for your own database table to get lots of fun features such as pagination. There's some very terse documentation here:
http://www.concrete5.org/documentation/developers/system/searching-...
I think basically what you do is load up this object, pass your SQL query to it, then it magically handles pagination for you. For example:
I haven't tested this out so I'm not 100% sure it works perfectly, but should get you most of the way there hopefully.
-Jordan
http://www.concrete5.org/documentation/developers/system/searching-...
I think basically what you do is load up this object, pass your SQL query to it, then it magically handles pagination for you. For example:
Loader::library('item_list'); $paintings = new DatabaseItemList(); $sql = "SELECT * FROM paintings"; $paintings->setQuery($sql); if ($paintings->getSummary()->pages > 1) { $paginator = $paintings->getPagination(); $pageListing = $paginator->getPages(); } $onePageOfPaintings = $paintings->getPage(); //etc...
I haven't tested this out so I'm not 100% sure it works perfectly, but should get you most of the way there hopefully.
-Jordan
Right on the money. Exactly what I was looking for.
Thanks to all of you.
Thanks to all of you.
I keep getting this error:
Fatal error: Call to protected method DatabaseItemList::setQuery() from context 'SinglePageController' for my single pages controller- what function is this supposed to be in?
Fatal error: Call to protected method DatabaseItemList::setQuery() from context 'SinglePageController' for my single pages controller- what function is this supposed to be in?
Oops, sorry about that. Looks like you need to create a new class first -- same basic idea, just the code is a bit more verbose:
Loader::library('item_list'); class PaintingList extends DatabaseItemList { public function __construct($query) { $this->setQuery($query); } } $sql = "SELECT * FROM paintings" $paintings = new PaintingList($sql); if ($paintings->getSummary()->pages > 1) { $paginator = $paintings->getPagination(); $pageListing = $paginator->getPages(); } $onePageOfPaintings = $paintings->getPage(); //etc...