2010年8月30日星期一

Re: [fw-db] Zend_Db_Table sequences and MySql problem


On Aug 30, 2010, at 6:39 AM, Tantius, Richard wrote:

The only problem, now I need to use ZendX_Db_Table instead of Zend_Db_Table in my whole application. My question is, is there maybe a more efficient way instead of introducing a whole new class level to my application, just to make Zend ignore sequences when working with MySql?

It is natural and intended usage of most object-oriented frameworks to extend classes when you need to add custom functionality.  Yes, you need to use your custom class by editing your concrete table class declarations.  It shouldn't take you more than a few minutes to make these edits.

Here's how I'd do it in vim:

:cd application/models
:n `grep -r -l --include=*.php extends.Zend_Db_Table_Abstract .`
/extends Zend
c$extends MyProject_AbstractTable
:n
n
.

Repeat the last three steps until you've reached the last of your table classes.

Here's how I'd write the custom Table class, simply overriding a protected function from the base class:

abstract class MyProject_AbstractTable extends Zend_Db_Table_Abstract
{
  protected function _setSequence($sequence)
  {
    if ($this->_db instanceof Zend_Db_Adapter_Pdo_Mysql || $this->_db instanceof Zend_Db_Adapter_Mysqli)
    {
      $sequence = (bool) $sequence;
    }
    $this->_sequence = $sequence;
    return $this;
  }
}

Regards,
Bill Karwin

没有评论: