php框架 zend,模型部分的php设计模式[php zend框架]
編輯
針對這一評論:
如果我有一個“select*from x”,如何跳過獲取已加載的記錄?
不能在查詢本身中執行,但可以在將行加載到實體對象中的邏輯中執行。在偽代碼中:
class Person {}
class PersonMapper {
protected $identity_map = array();
function load($row) {
if (!isset($this->identity_map[$row['id']])) {
$person = new Person();
foreach ($row as $key => $value) {
$person->$key = $value;
}
$this->identity_map[$row['id']] = $person;
}
return $this->identity_map[$row['id']];
}
}
class MappingIterator {
function __construct($resultset, $mapper) {
$this->resultset = $resultset;
$this->mapper = $mapper;
}
function next() {
$row = next($this->resultset);
if ($row) {
return $this->mapper->load($row);
}
}
}
實際上,你可能希望
MappingIterator
實施
Iterator
,但為了簡潔我跳過了。
總結
以上是生活随笔為你收集整理的php框架 zend,模型部分的php设计模式[php zend框架]的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Showdoc 搭建项目 API 文档系
- 下一篇: php程序怎么调试,你是怎么调试PHP代