EAV模型的创建
跟简单模型的创建差不多(继承类不同),数据库表的结构很大区别
1、创建基本模型类(类型数据绑定),设置配置文件启用基本模型
2、创建资源模型(与数据库对话),设置配置文件启用资源模型
<!--创建一个组名为hello_eav模型-->
<hello-eav>
<!--模型的位置在rib/Hello/Model-->
<class>rib_Hello_Model</class>
<!--资源模型是helloworld-eav_mysql4-->
<resourceModel>hello-eav_mysql4</resourceModel>
</hello-eav>
<hello-eav_mysql4>
<!--资源模型的位置在rib_Hello_Model_Resource_Eav_Mysql4,名字为:blogpost.php-->
<class>rib_Hello_Model_Resource_Eav_Mysql4</class>
<entities>
<blogpost>
<!--数据库名为eavblog_posts-->
<table>eavblog_posts</table>
</blogpost>
</entities>
</hello-eav_mysql4>
与简单的资源模型不同,EAV的资源模型:
<?php
class rib_Hello_Model_Resource_Eav_Mysql4_Blogpost extends Mage_Eav_Model_Entity_Abstract
{
public function _construct()
{
$resource = Mage::getSingleton('core/resource');
// hello_eavblogpost:组名_模型名
$this->setType('hello_eavblogpost');
$this->setConnection(
$resource->getConnection('hello-eav_read'),
$resource->getConnection('hello-eav_write')
);
}
}
?>
3、配置参数,让magento自动创建数据库表等数据
配置config:
<resources>
<!--资源配置标签-->
<!--hello-eav模型的资源配置-->
<hello-eav_setup>
<setup>
<module>rib_Hello</module>
<!--资源类文件的位置-->
<class>rib_Hello_Model_Entity_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</hello-eav_setup>
<hello-eav_write>
<connection>
<use>default_write</use>
</connection>
</hello-eav_write>
<hello-eav_read>
<connection>
<use>default_read</use>
</connection>
</hello-eav_read>
</resources>
4、修改脚本,添加实体
5、修改脚本,使用magento的函数createEntityTables()创建实体数据库表
6、添加属性:使用getDefaultEntities()函数添加属性,在脚本中执行installEntities()执行添加属性
7、在control中创建方法,可以对EAV模型进行增删查改操作。
eg:查询某调属性值显示:

系统配置
了解这个过程的操作,不知道这个实际操作的含义
1、添加system.xml 的配置文件
2、添加这个组件的helper
3、添加新的字段
4、添加组
5、添加选项
6、添加组中的数据
最后添加好的标签选项:

重写block
1、将重写的block放在Block下
2、修改config文件
//在global下
<!--重写block-->
<blocks>
<!--组名-->
<catalog>
<!--固定,寻找被替换的block-->
<rewrite>
<!--breadcrumbs是被替换的block名,里面是路径-->
<breadcrumbs>Infinity_Catalog_Block_Breadcrumbs</breadcrumbs>
</rewrite>
</catalog>
</blocks>
重写控制器(shopping的控制器)
1、修改config文件:
<global>
<rewrite>
<Infinity_Shopping_cart>
<from><![CDATA[#^/checkout/cart/#]]></from>
<to>/shopping/cart/</to>
</Infinity_Shopping_cart>
</rewrite>
</global>
<frontend>
2、在使用controller 的时候,可以包含magento里的controller类,在控制器中直接修改这个类
require_once 'Mage/Checkout/controllers/CartController.php';
重写model
1、在config中设置重写配置:
<models>
//组名
<customer>
//设置重写model
<rewrite>
//重写的类名是:Customer,路径:Infinity_Customer_Model_Customer
<customer>Infinity_Customer_Model_Customer</customer>
</rewrite>
</customer>
</models>
2、在重写文件中,继承原来的model类,重写方法或者增添model方法
3、问题:怎么使用已经修改的model类方法?
重写helper
<helpers>
<customer>
<rewrite>
//重写helper的文件位置
<data>Infinity_Customer_Helper_Customer_Data</data>
</rewrite>
</customer>
</helpers>
1013

被折叠的 条评论
为什么被折叠?



