Extended Question: Why should I use data mapper / Db_Table_Row, where as DbTable is capable of handling most of the basic tasks for data manipulation.个
我目前正在学习ZF v1.11
对于数据库操作,我 for each 表创建了DbTable.例如,"用户"表由应用程序_Model_DbTable_users表示,其中没有附加代码.
在处理数据时,我可以使用:
<?php
$uTable = new Application_Model_DbTable_Users();
$newUid = $uTable->insert(array('name'=>'Old Name', 'email'=>''));
$user = $uTable->find($newUid)->current();
// Then I can use $user which is instance of Table_Row
$user->name = "New Name";
$user->email = "email@addr.com";
$user->save();
我的问题是,何时需要定义行类(假设在ZF教程中将Table_Row称为DataMapper)
// By, adding this to the DbTable class
protected $_rowClass = 'Application_Model_User';
for each 实体创建一个Row类有什么好处?有谁能告诉我这方面的最佳实践吗.