2008年7月28日星期一

Re: [fw-db] Custom Row Class - _get() from two tiers

SiCo007 wrote:
>
> I guess my question is how do I fake an object without creating one and
> copying the table data to it then using another __get() method in that
> class.
>

I would say this is too much magic, and you're probably going to make your
app harder to maintain as a result, rather than easier.

But to answer your question, here's a solution that works for the case you
described with __get(). Though I suspect you mean for it to work with
toArray() and other operations too. The solution below doesn't handle that.

class CustomRow extends Zend_Db_Table_Row_Abstract
{
protected $_prefixes = array('product', 'variant');
protected $_prefix = 'product';

protected function setPrefix($prefix)
{
$this->_prefix = $prefix;
}

public function __get($key)
{
if (!array_key_exists($key, $this->_data)) {
if (in_array($key, $this->_prefixes)) {
$subRow = clone $this;
$subRow->setPrefix($key);
return $subRow;
}
$key = "{$this->_prefix}_{$key}";
}
return parent::__get($key);
}
}

Regards,
Bill Karwin
--
View this message in context: http://www.nabble.com/Custom-Row-Class---_get%28%29-from-two-tiers-tp18697512p18698709.html
Sent from the Zend DB mailing list archive at Nabble.com.

没有评论: