For those caring, I just posted some quick documentation for the pagination component at my assembla space. More docs will follow (including extensive phpdoc docblocks I hope).
A propos
- About me: Geoffrey Bachelet
- Profile LinkedIn
To content | To menu | To search
Monday 1 October 2007
By Geoffrey on Monday 1 October 2007, 12:44 - Coding
For those caring, I just posted some quick documentation for the pagination component at my assembla space. More docs will follow (including extensive phpdoc docblocks I hope).
Sunday 30 September 2007
By Geoffrey on Sunday 30 September 2007, 01:28 - Coding
I just released on riskle's assembla space a new version of my pagination component for the Zend Framework which you can download right now:
This release fixes a nasty bug in Riskle_Db_Table::fetchCols which prevented from retrieving the right count of cols involved in the query.
The table component has also been slightly rewritten following Erik's suggestion to move the parent mapping into _fetch. The parent mapping itself has been improved to allow "multi level" table joining. This will be best explained with an example:
Say you have three table, Foo, Bar and Quux, and you would like to execute the following query:
SELECT * FROM Foo JOIN Bar ON Foo.bar_id = Bar.id JOIN Quux ON Bar.quux_id = Quux.id
This is now possible with the following mapping (in Foo's class of course):
array(
'Bar' => array('local' => 'bar_id', 'remote' => 'id'),
'Quux' => array('local' => 'quux_id', 'remote' => 'Quux.id'),
);
Easy heh ?
As usual, any comments are appreciated, and please note that this code is released under the same license as the ZF itself, the new-bsd license.
Sunday 23 September 2007
By Geoffrey on Sunday 23 September 2007, 00:07 - Coding
UPDATE: new version (r105) available.
The component was given a little rewrite as expected, but maybe a little bit later than I would have wanted to :-) So it now has its own Rowclass proxy from which you can pull various infos such as current page, page range, next page, etc all exposed as getter methods (that is, getCurrentPage, getPageRange, getNextPage, etc), which you won't really have to worry about since the brand new view helper will take care of that for you. Usage has changed a little, bit, so let's first have a look at what's happening from the controller point of view:
$table = new Riskle_Db_Table_Paginate(new Table, $this->_getParam('page'));
$this->view->rowset = $table->fetchAll();
Not much changed here, except we don't need anymore to call getPaginationInfos(). Nice ! Now the big part, the view:
$this->paginate($this->rowset);
echo $this->paginate()->previous();
echo $this->paginate()->navigation();
echo $this->paginate()->next();
The view helper uses the neat composite helper trick from naneau - which is a really cool trick, great job naneau my fellow no-more-a-bunny. The first call inits the helper, feeding him the necessary rowset to work on, then you just have to call the methods you need to draw the navigation links. As you may expect, previous and next method will return nothing if no page is available (actually, they return their second argument, which defaults to an empty string).
Also, it's worth noting that the bundled Riskle_Db_Table features the patch from Erik, as well as a totally rewritten fetchCols method (now uses a straight Zend_Db_Select object instead of the ugly trick it used to use).
My code is no longer available on subversion, I moved the project to assembla. Instead ou can download this component from the riskle space's files board (direct download), the file contains all classes needed for the component to work, just unzip it in your include_path and you're set.
As usual, any comments are more than welcome.
Tuesday 31 July 2007
By Geoffrey on Tuesday 31 July 2007, 11:33 - Coding
UPDATE
A new version of this component is available.
I have a new version of my pagination component which solve the issue previously pointed out by Guy. This update comes along with a subclassed version of Zend_Db_Table which allows counting and specific columns selection respectively via the fetchCount() and fetchCols() methods. Btw, the fetchCols() method is very hackish at the moment, and I'll certainly end up with rewriting it using a plain Zend_Db_Select statement.
As always, any comment is appreciated. I'm thinking of subclassing the Rowset class to fill it with pagination info getters like getPageCount(), getNextPage(), etc, like in Symfony for those knowing, instead of relying on a getPaginationInfo() method. Future improvements will also include more view helper magic.
Also, I came up with a small new Riskle_Pattern namespace which I use to implement commonly used patterns, such as the Proxy Pattern. I'm not yet sure of the pertinence of this thing, so any comments are yet again very much appreciated on this topic :-)
Sunday 15 July 2007
By Geoffrey on Sunday 15 July 2007, 11:38 - Coding
Yesterday I came up with a small pagination component for the Zend Frameworks. It implements the Proxy pattern around a Zend_Db_Table object, and overloads the fetchAll method. The main problem I encountered here was to retrieve the total number of rows for the table. I'm using a Zend_Db_Select query for now, but I'll have to improve that. The component also features a view helper to draw the pagination links.
You'll find the code for the component and the view helper on my SVN.
And here is how it is used in the controller:
public function indexAction() {
$urls = new Riskle_Db_Table_Paginate(new Urls, $this->_getParam('page'));
$this->view->urlsList = $urls->fetchAll(null, 'datetime DESC');
$this->view->paginationInfos = $urls->getPaginationInfos();
}
The view helper takes paginationInfos as an argument:
echo $this->paginate($this->paginationInfos);
UPDATE
As pointed out by Guy, the _getPageCount method does not actually takes care of the $where condition, thus rendering the class inefficient as getting the real totel number of items. This issue will be adressed in an upcoming version of the class :-)
UPDATE
There's an updated version of this component available.