Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've encountered scenarios where I've wanted to do this. Here is the solution that I've used:</p> <ul> <li>Created an extended row class for Zend_Db_Table_Row and overloaded the __get() and __set() super-methods</li> <li>In the specific classes/tables that I want to use date objects, created the appropriate methods to do the heavy lifting</li> </ul> <p>Here is a dumbed-down version of the extended row class that I use on my projects:</p> <pre><code>/** * @category FireUp * @package FireUp_Db * @copyright Copyright (c) 2007-2009 Fire Up Media, Inc. (http://www.fireup.net) * @license http://dev.fireup.net/license/mit MIT License * @uses Zend_Db_Table_Row */ class FireUp_Db_Table_Row extends Zend_Db_Table_Row_Abstract { /** * Retrieve row field value * * Checks for the existence of a special method to apply additional handling for the field data and calls the method if it exists * * @param string $columnName The user-specified column name. * @return string The corresponding column value. * @throws Zend_Db_Table_Row_Exception if the $columnName is not a column in the row. */ public function __get($key) { $inflector = new Zend_Filter_Word_UnderscoreToCamelCase(); $method = '_get' . $inflector-&gt;filter($key); if (method_exists($this, $method)) { return $this-&gt;{$method}(); } return parent::__get($key); } /** * Set row field value * * Checks for the existence of a special method to apply additional handling for the field data and calls the method if it exists * * @param string $columnName The column key. * @param mixed $value The value for the property. * @return void * @throws Zend_Db_Table_Row_Exception */ public function __set($key, $value) { $inflector = new Zend_Filter_Word_UnderscoreToCamelCase(); $method = '_set' . $inflector-&gt;filter($key); if (method_exists($this, $method)) { return $this-&gt;{$method}($value); } return parent::__set($key, $value); } } </code></pre> <p>For our individual table classes, we override the functions as such:</p> <pre><code>class EntityRecord extends FireUp_Db_Table_Row { protected function _getDateCreated() { return new Zend_Date($this-&gt;_data['date_created'], Zend_Date::ISO_8601); } protected function _setDateCreated($value) { if ($value instanceof Zend_Date) { $value = $value-&gt;toString('YYYY-MM-dd HH:mm:ss'); } $this-&gt;_data['date_created'] = $value; $this-&gt;_modifiedFields['date_created'] = true; } } </code></pre> <p>Now, creating a new Zend_Date object everytime that the field would be accessed has some overhead, so in our classes, we take additional measures to cache the date objects, etc, but I didn't want that to get in the way of showing you the solution.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload