2019.1.28 学习总结

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> 

关于重写最大的问题:在重写model类、controller类、helper类中,重写的后怎么使用重写后的类;重写类跟普通类继承magento类后,再进行继承有什么区别?

同名覆盖重写法 :顾名思义,直接把magento内置类复制在本组(Module)local目录下(路径要与原路径一样),这样的话,会优先加载local下的重写类(只能重写 Block、Model)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值