magento---EAV模型----总结!!
数据库添加eav模型
教程地址
http://magentobbs.com/?q=content/%E6%B7%BB%E5%8A%A0%E5%AE%9E%E4%BD%93%E7%B1%
BB%E5%9E%8B
eav模型原理:
产品表----(entity_type_id)---->属性表-----(attribute_id)----->值表
在上面这个关系中,
安装数据库
1
设置EntityType,主要是设置一些在安装过程需要用到的值。
$installer->addEntityType('helloworld_eavblogpost',Array(
//entity_mode is the URL you'd pass into a Mage::getModel() call
'entity_model' =>'helloworld-eav/eavblogpost',
//blank for now
'attribute_model' =>'',
//table refers to the resource URI helloworld-eav/blogpost
//<helloworld-eav_mysql4>…<blogpost><table>eavblog_posts</table>
'table' =>'helloworld-eav/blogpost',
//blank for now, but can also be eav/entity_increment_numeric
'increment_model' =>'',
//appears that this needs to be/can be above "1" if we're using
eav/entity_increment_numeric
'increment_per_store' =>'0'
));
设置type----->设置model,table,为表的创建,model的读取提供值!!
总之,作为一个独立个体,设置值,为了得到在安装数据库过程中要用到的数据。
2
创建表
$this->getTable应该就是1过程中对table的值的设置的读取。
$installer->createEntityTables(
$this->getTable('helloworld-eav/blogpost')
);
创建表:
eavblog_posts
eavblog_posts_datetime
eavblog_posts_decimal
eavblog_posts_int
eavblog_posts_text
eavblog_posts_varchar
同时
eav_attribute_set多了一条数据。
在这个过程中,创建了主表和属性类型表,应该是这样
3
设置属性。
在这个过程中创建属性表
class Zhlmmc_Helloworld_Model_Setup_Entity_Setup extends
Mage_Eav_Model_Entity_Setup {
public function getDefaultEntities()
{ return array (
'helloworld_eavblogpost' => array(
'entity_model' => 'helloworld-eav/eavblogpost',
'attribute_model' => '',
'table' => 'helloworld-eav/blogpost',
'attributes' => array(
'title' => array(
//the EAV attribute type, NOT a mysql varchar
'type' => 'varchar',
'backend' => '',
'frontend' => '',
'label' => 'Title',
'input' => 'text',
'class' => '',
'source' => '',
// store scope == 0
// global scope == 1
// website scope == 2
'global' => 0,
'visible' => true,
'required' => true,
'user_defined' => true,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'unique' => false,
在此过程中,helloworld_eavblogpost为type值,也就是在在资源模型对应的类中使用
setType()函数中的参数,当然也要和sql/helloword-eav_setip/mysql4-install-
0.1.0.php 中addEntityType里面的值对应,在这里,table,attribute都要设置,值和
addEntityType的保持一致,不同的是多了一个attribute的值,
'attributes' => array(
'title' => array(
//the EAV attribute type, NOT a mysql varchar
'type' => 'varchar',
这里的表的内容,相当于正常表中的列!!
使用eav模型:
步骤:
1
编写model
2
resourcemodel
<helloworld-eav_mysql4>
<class>Zhlmmc_Helloworld_Model_Resource_Eav_Mysql4</class>
<entities>
<blogpost>
<table>eavblog_posts</table>
</blogpost>
</entities>
</helloworld-eav_mysql4>
3
资源--读写适配器
<resources>
<!– … ->
<helloworld-eav_write>
<connection>
<use>default_write</use>
</connection>
</helloworld-eav_write>
<helloworld-eav_read>
<connection>
<use>default_read</use>
</connection>
</helloworld-eav_read>
</resources>
4
设置相应的资源模型类
所以我们创建相应的资源模型类
File: app/code/local/Zhlmmc/Helloworld/Model/Resource/Eav/Mysql4/Blogpost.php
class Zhlmmc_Helloworld_Model_Resource_Eav_Mysql4_Blogpost extends
Mage_Eav_Model_Entity_Abstract
{
public function _construct()
{
$resource = Mage::getSingleton('core/resource');
$this->setType('helloworld_eavblogpost');
$this->setConnection(
$resource->getConnection('helloworld-eav_read'),
$resource->getConnection('helloworld-eav_write')
);
}
}
5
记得添加模型集合
class Zhlmmc_Helloworld_Model_Resource_Eav_Mysql4_Blogpost_Collection extends Mage_Eav_Model_Entity_Collection_Abstract
{
protected function _construct()
{
$this->_init('helloworld-eav/eavblogpost', 'helloworld-eav/blogpost');
}
}
6
填写数据。
$weblog2 = Mage::getModel('helloworld-eav/eavblogpost');
$weblog2->setTitle('This is a test '.$i);
$weblog2->save();
7
读取数据
public function eavShowcollectionAction() {
$weblog2 = Mage::getModel('helloworld-eav/eavblogpost');
$entries = $weblog2->getCollection()->addAttributeToSelect('title');
$entries->load();
foreach($entries as $entry)
{
// var_dump($entry->getData());
echo '<h1>'.$entry->getTitle().'</h1>';
}
echo '<br>Done<br>';
}
magento---EAV模型----总结!!相关推荐
- magento EAV 模型理解
EAV模型是Zend框架的基础,而Magento项目又是建立在Zend框架的基础上的,所有了解EAV有助于了解Magento的架构原理,在开发Magento相关应用时非常有用. EAV : Entit ...
- Magento开发文档(七):Magento EAV模型
在第一篇介绍Magento ORM的文章中,我们提到过Magento拥有两类模型.普通的模型及Entity Attribute Value(EAV)模型.这里首先搞清楚它们之前的一些关系. 所有的Ma ...
- Magento 2数据库EAV模型结构
EAV模型是一种数据模型 ,用于描述实体的数量预计会很大,但事实上,实体中要使用的属性数量并不多. Magento 2这么设计是为了灵活性,在不影响主干的基础上,任意新增删除属性. EAV模型(E ...
- 【转】Magento 2数据库EAV模型结构
EAV模型是一种数据模型 ,用于描述实体的数量预计会很大,但事实上,实体中要使用的属性数量并不多. Magento 2这么设计是为了灵活性,在不影响主干的基础上,任意新增删除属性. EAV模型(E ...
- java eav_动态自定义字段属性–Magento的EAV模型 | 学步园
EAV : Entity - Attribute - Value 的缩写,是数据库模型的一种,使用eav建模的好处是可以动态为数据模型增加或移除属性. 1. 问题提出: 假设需要定义一个实体Custo ...
- Magento 数据表结构 EAV模型详解
EAV : Entity - Attribute - Value的缩写,是数据库模型的一种,使用eav建模的好处是可以动态为数据模型增加或移除属性. 1.问题提出: 假设需要定义一个实体Custome ...
- Magento的EAV模型窥探
EAV : Entity - Attribute - Value 的缩写,是数据库模型的一种,使用eav建模的好处是可以动态为数据模型增加或移除属性. [color=#BF0000][b]1. 问题提 ...
- mysql eav_Magento的EAV模型窥探
1. 问题提出: 假设需要定义一个实体Customer的信息,通常我们只要定义一个表为customer,并定义相应的属性即可.倘若某天需要为customer增加一个新的属性如"毕业学校&qu ...
- java eav模式_Magento 2中EAV模型的理解
今天我将要讲述Magento 2中的EAV模型,Magento 2的数据库使用的技术是一个 以实体-属性-值得模型的一种数据模型简称:EAV模型 实体-属性-值(Entity-Attribute-Va ...
- 使用 Eav 模型构建可无限扩展的数据存储能力
举个例子 假设要做一个电商的商品管理,我们先卖一些衣服,需要管理衣服的尺码.颜色.款式等信息,有一天需要卖电脑了,电脑需要 主板.CPU.显卡.内存.硬盘.散热 等信息,过几天又需要卖手机了,手机有 ...
最新文章
- MyBatis学习总结(二)——使用MyBatis对表执行CRUD操作
- HTML5之内嵌框架
- Windows事件等待学习笔记(一)—— 临界区自旋锁
- Glib 对 C 函数进行单元测试
- Android实现动画Dialog
- 介绍自己以及github注册流程
- 相乘的c语言,c语言矩阵相乘
- 学习vue3系列ref
- 单结晶体管的导电特性_二极管的导电特性
- C++ 哪些不能为虚函数
- 用“看板图”实现敏捷项目的可视化
- PyCharm:Error running xxx: Cannot run program D:\Python27\python.exe
- ActiveX控件注册的几种方法
- 查看linux有多少线程总数,linux线程总数
- 开关型直流电源比线性直流电源效率高的原因?
- LibPcap经常丢包怎么办?
- 为什么人工智能工程师被戏称为“调参侠”?
- 妹子:为什么我要找个程序员做老公?
- 水管工游戏---啊哈算法
- Linux 网络状态工具 ss 详解,比netstat更强大
热门文章
- 夜神模拟器:新建android模拟器并安装apk文件
- 统信 UOS 20 初体验
- linux open_namei,刚学Linux 想问问这个程序写的什么 有大佬帮帮吗
- 【待更新】GPU 保存模型参数,GPU 加载模型参数
- oracle数据库19C更改字体的大小及字体名称
- 测试需要掌握的数据库sql知识(一):基本语句操作
- 【中危】未加密的__VIEWSTATE参数
- Codeforces Beta Round #91 div.2 滑稽场 A-D
- 【Java】基础知识部分
- 笔试题算法系列(三)百度钓鱼比赛