我有一个快速的问题。我正在使用 Zend Framework 1,并且正在使用 Data Mapper。这是我的代码:
<?php
// application/model/Pos.php
class Application_Model_Pos extends Zend_Db_Table_Abstract
{
protected $_name = 'pos';
}
// application/model/MapperAbstract.php
abstract class Application_Model_MapperAbstract
{
private $_dbTable;
public function __construct(Zend_Db_Table_Abstract $dbTable)
{
$this->_dbTable = $dbTable;
}
public function findById($id)
{
$select = $this->_dbTable()->select()->where('id = ?', $id)->limit(1);
$row = $this->_dbTable()->fetchAll($select)->toArray();
if(!empty($row))
{
$this->_createEntity($row);
}
}
protected function _createEntity(array $row);
}
// application/model/PosMapper.php
class Application_Model_PosMapper extends Application_Model_MapperAbstract
{
public function __construct()
{
parent::__construct(new Application_Model_Pos());
}
protected function _createEntity(array $row)
{
return new Sb_Pos($row['name']);
}
// application/library/Sb/Pos.php
class Sb_Pos
{
public function __construct($name)
{
$this->_name = $name;
}
}
?>
有了这段代码,我应该在哪里处理表依赖关系?一个映射器应该知道另一个映射器吗?我需要服务层吗?
谢谢你的帮助。