2008年12月15日星期一

[fw-db] Zend_Db_Table_Abstract syntactic sugar proposal

Hello,

I've just begun exploring Zend_Db_Table_Abstract and found myself
passing an array of fields to its select() method so that a final DB
result set would only include the specified fields:

public function getByDestination($continentId, $countryId, $cityId)
{
return $this->fetchAll(
$this->select(array('name'))
->where('continent_id = ?', $continentId)
->where('country_id = ?', $countryId)
->where('city_id = ?', $cityId)
->order('name ASC')
->limit(10)
);
}

Unfortunately this isn't working right now so I tried modifying the
source of Zend_Db_Table_Abstract and it turns out that what I did works
quite well for me. Here's what I did:

public function select($columns)
{
require_once 'Zend/Db/Table/Select.php';
$select = new Zend_Db_Table_Select($this);
$select->from($this->_name, $columns);
return $select;
}

Now, as I said, these are my first lines of code using this ZF component
so I'd like to hear your opinion about it or maybe existing alternatives
to what I did.


Cheers,
Ionut

没有评论: