2008年12月15日星期一

Re: [fw-db] Zend_Db_Table_Abstract syntactic sugar proposal

If I were you I wouldn't change the Zend source code. But write your own
class en overwrite this select function. Something like this:

class MyTableClass_Db_Table extends Zend_Db_Table_Abstract {
public function select($columns) {
...
}
}

class DestinationModel extends MyTableClass_Db_Table
{
...
}


Ionut Gabriel Stan-2 wrote:
>
> 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
>
>


-----
visit my website at http://www.phpscriptor.com/ http://www.phpscriptor.com/
--
View this message in context: http://www.nabble.com/Zend_Db_Table_Abstract-syntactic-sugar-proposal-tp21013477p21014036.html
Sent from the Zend DB mailing list archive at Nabble.com.

没有评论: