迭代器模式,在不需要了解内部实现的前提下,遍历一个聚合对象的内部元素。相比于传统的编程模式,迭代器模式可以隐藏遍历元素所需要的操作。
AllHacl.php
php namespace Baobab; class AllHacl implements \iterator{ protected $ids;protected $index;//当前位置 function __construct(){ $db = Factory::getDatabase('ha_cl'); $result = $db->query('select ID from ha_cl'); $this->ids = $result->fetch_all(MYSQLI_ASSOC); }
/**
* 返回当前元素
*/ function current(){ $id = $this->ids[$this->index]['ID']; return Factory::getHacl($id); }
/**
* 向前移动到下一个元素
*/ function next(){ $this->index ++; } /** * 返回到迭代器的第一个元素 */ function rewind(){ $this->index = 0; } /** * 查询当前位置是否有数据 */ function valid(){ return $this->index - count($this->ids); }
/**
* 返回当前元素的键
*/ function key(){ return $this->index; } }
index.php
$hacls = new \Baobab\AllHacl(); foreach($hacls as $hacl){ var_dump($hacl->haclname); }
Hacl类相关内容参考数据对象映射模式。http://www.cnblogs.com/tianxintian22/p/5232016.html
Magento是一套专业开源的PHP电子商务系统。Magento设计得非常灵活,具有模块化架构体系和丰富的功能。易于与第三方应用系统无缝集成。Magento开源网店系统的特点主要分以下几大类,网站管理促销和工具国际化支持SEO搜索引擎优化结账方式运输快递支付方式客户服务用户帐户目录管理目录浏览产品展示分析和报表Magento 1.6 主要包含以下新特性:•持久性购物 - 为不同的
立即学习“PHP免费学习笔记(深入)”;










