On Jan 26, 2007, at 3:34 PM, Bill Karwin wrote:

Taylor Barstow wrote:
Hi,

I'd like to add support for subclassing Zend_Db_Table_Row. Is this already in the works or is this a worthwhile thing for me to work on? It would probably be a pretty small patch.

Hmm, I meant to send the following to the list, but my Sent folder indicates I sent it only to Taylor. I'll try again...

This is already in the works.
See for example:

http://framework.zend.com/issues/browse/ZF-38 Zend_Db_Table should allow custom Row objects http://framework.zend.com/issues/browse/ZF-337 Zend_Db_Table_Row: implement array iterator for DB_ROW
http://framework.zend.com/wiki/x/bx0 (proposal)

In addition to what was outlined in the proposal and in an attempt to create a more automated approach to extended Row and Rowset classes, we also added this to Mc_Db_Table:

==================
    protected function _setup($class = null)
    {

        if (null !== $class) {
            $rowClass = PROJECT_CLASS_ROOT . '_Db_Table_Row_' . $class;
            if (Mc::isClassReadable($rowClass)) {
                $this->setTableRowClass($rowClass);
            }

$rowsetClass = PROJECT_CLASS_ROOT . '_Db_Table_Rowset_' . $class;
            if (Mc::isClassReadable($rowsetClass)) {
                $this->setTableRowClass($rowsetClass);
            }
        }

        parent::_setup();
    }
==================

In our models we call it like:
==================
        protected function _setup()
    {
        parent::_setup(__CLASS__);
    }
==================

This way if we'd like to extend the Row or Rowset of a Model, all we have to do is create the appropriate class. I could not find a way to automate this without the __CLASS__ from the child class. Does anyone know a way to keep it all in the extended Table class versus overriding the setup yet again in the Model?


-Will

Reply via email to