This is straight from the Zend Quick Start Guide. My question is: why do you need the setDbTable() method when the getDbTable() method assigns a default Zend_Db_Table object? If you know that this mapper uses a specific table, why even offer the ability to potentially use the βwrongβ table through setDbTable() ? What flexibility do you get when you can set up a table if the rest of the code ( find() , fetchAll() , etc.) is fetchAll() to the Guestbook ?
class Application_Model_GuestbookMapper { protected $_dbTable; public function setDbTable($dbTable) { if (is_string($dbTable)) { $dbTable = new $dbTable(); } if (!$dbTable instanceof Zend_Db_Table_Abstract) { throw new Exception('Invalid table data gateway provided'); } $this->_dbTable = $dbTable; return $this; } public function getDbTable() { if (null === $this->_dbTable) { $this->setDbTable('Application_Model_DbTable_Guestbook'); } return $this->_dbTable; } ... GUESTBOOK SPECIFIC CODE ... } class Application_Model_DbTable_Guestbook extends Zend_Db_Table_Abstract { protected $_name = 'guestbook_table'; }
source share