Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple Tables in Zend based on the Quick Start Guide Example
    text
    copied!<p>I am new to Zend and have been attempting to follow the <a href="http://framework.zend.com/manual/en/learning.quickstart.create-model.html" rel="nofollow">Zend Quick Start Guide's example</a> of using Data Mappers and extending Zend_Db_Table_Abstract. I think I've grasped the general concepts, but I am now wondering, how I would go about modifying the guide's example code to allow for multiple tables.</p> <p>Here is the part of the code I am currently interested in modifying:</p> <pre><code>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-&gt;_dbTable = $dbTable; return $this; } public function getDbTable() { if (null === $this-&gt;_dbTable) { $this-&gt;setDbTable('Application_Model_DbTable_Guestbook'); } return $this-&gt;_dbTable; } </code></pre> <p>I have changed it to this:</p> <pre><code>protected $_dbTables; public function setDbTable($dbTable, $tableName) { if (is_string($dbTable)) { $dbTable = new $dbTable(); } if (!$dbTable instanceof Zend_Db_Table_Abstract) { throw new Exception('Invalid table data gateway provided'); } $this-&gt;_dbTables[$tableName] = $dbTable; return $this; } public function getDbTables() { if (null === $this-&gt;_dbTables) { $this-&gt;setDbTable('Application_Model_DbTable_Courses', 'courses'); $this-&gt;setDbTable('Application_Model_DbTable_CourseTimes', 'course_times'); } return $this-&gt;_dbTables; } </code></pre> <p>Is this a correct way to go about implementing multiple tables within the Data Mapper pattern or would you do it differently? Thanks for your help in advance!</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