to hook into pre- and post- logic.
For Zend_Db_Table_Abstract based classes, you can override (but dont
forget to call the parent method of)
Zend_Db_Table_Abstract::insert()
Zend_Db_Table_Abstract::update()
If you need more granular control, you would ideally extend
Zend_Db_Table_Row_Abstract. In this class you can implement logic at
Zend_Db_Table_Row_Abstract::_insert();
Zend_Db_Table_Row_Abstract::_postInsert();
Zend_Db_Table_Row_Abstract::_udpate();
Zend_Db_Table_Row_Abstract::_postUpdate();
Zend_Db_Table_Row_Abstract::_delete();
Zend_Db_Table_Row_Abstract::_postDelete();
Each of these methods are empty inside the abstract, so there would be
no need to call parent:: in them. You also have both the _data and
_cleanData available to you in the respective methods so that you can
see what the current data is, and what the current data in the actual
database is. I generally opt for putting this kind of logic inside the
Row_Abstract classes.
Hope this helps,
Ralph
milesap wrote:
> Hello Everyone,
>
> I was wondering if there is a way to alter the values returned from MySQL
> within the Zend_Db_Table_Abstract class. Bear with me, I'll give you an
> example of what I mean! I fetch rows like this:
>
> $billing = new Billing(); //(Zend_Db_Table_Abstract class)
> $getRow = $billing->fetchRow($billing->select()->where('id = ?', 1));
>
>
> The above returns all columns in my billing table, say transaction and price
> where id = 1, good so far. Now is it possible to alter, say price, in the
> Zend_Db_Table_Abstract class? I know how to alter data for update and insert
> in Zend_Db_Table_Abstract:
>
> public function update(array $data)
> {
> $data['price'] = '$10';
> return parent::update($data);
> }
>
>
> but not sure how to do this for data that's retrieved from the database. Can
> anyone point me in the right direction or have a solution, I just can't
> figure it out. Thanks in advance!
没有评论:
发表评论