ZendDbTable has been significantly enhanced for version 1.5, mainly by Simon Mundy and is really really good. It’s going to take me a while to poke around and find out all the new nuances!
However, I did find one gotcha that has affected me on my main project at work.
If you happen to have extended ZendDbTableAbstract::fetch() for some reason or another, be aware that it’s changed in version 1.5.
It was:
[php]
/**
* Support method for fetching rows.
*
* @param string|array $where OPTIONAL An SQL WHERE clause.
* @param string|array $order OPTIONAL An SQL ORDER clause.
* @param int $count OPTIONAL An SQL LIMIT count.
* @param int $offset OPTIONAL An SQL LIMIT offset.
* @return array The row results, in FETCH_ASSOC mode.
*/
protected function _fetch($where = null, $order = null, $count = null, $offset = null)
{
// lots of stuff
}
[/php]
and is now:
[php]
/**
* Support method for fetching rows.
*
* @param ZendDbTableSelect $select query options.
* @return array An array containing the row results in FETCHASSOC mode.
*/
protected function _fetch(Zend_Db_Table_Select $select)
{
// much less stuff
}
[/php]
Just a heads-up in case someone else has customised this function for their own needs.
Related to this, Ralph Eggert recently discovered something else related 1.5 changes when extending ZendDbTableAbstract and Simon Mundy helped out. The select object that is the parameter to _fetch() has a check in it to prevent you joining to another table. This is because if you join, you break the concept that a ZendDb_Table represents a single table. However, you can get around it using the function setIntegrityCheck() like this:
[php]
protected function fetch(ZendDbTableSelect $select)
{
// extend select
$select->setIntegrityCheck(false);
$select->join(// do stuff);
}
[/php]
The setIntegrityCheck() statement allows you to do a join in the select object and very cleverly puts the table object into read only mode, which is great.
Also, Example 10.136 of the ZendDbTable documentation has more information on how to use the $select to get back the data you actually want.
Posted by Rob on 30th January 2008 under Tips and Tricks | 5 Comments »