博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
magento 模块重写机制
阅读量:4199 次
发布时间:2019-05-26

本文共 2523 字,大约阅读时间需要 8 分钟。

由magento重写功能所想到的:

 

1.在etc/config.xml中

 第一层为<config>

 第二层为<module>,<global>,<admin>,<adminhtml>,<frontend>,<default>等。

 

2.重写内容

 

 

1>block--在config.xml文件中block重写的配置

 

<global>

<blocks>

<模块名>

<rewrite>

<重写的半类名>类名全名

 

如:

<global>

<blocks>

<catelog>

<rewrite>

<breadcrumbs>App_Catalog_Block_Breadcrumbs</breadcrumbs>

 

 

2>controller---在config.xml文件中的配置

 

 

<global>

<rewrite>

<你的控制器的名>

<from><![CDATA[#^/模块名/controller/#]]>  </from>

<to>/shopping/cart/</to>

 

例如:

 

<global>

<!-- This rewrite rule could be added to the database instead -->

<rewrite>

<!-- This is an identifier for your rewrite that should be unique -->

<!-- THIS IS THE CLASSNAME IN YOUR OWN CONTROLLER -->

<App_Shopping_cart>

<from><![CDATA[#^/checkout/cart/#]]></from>

<!--

- Shopping module matches the router frontname below - checkout_cart

matches the path to your controller Considering the router below,

"/shopping/cart/" will be "translated" to

"/App/Shopping/controllers/CartController.php" (?)

-->

<to>/shopping/cart/</to>

</App_Shopping_cart>

</rewrite>

<!--参考-->

<blocks>

             <catalog><class>Mage_Catalog_Block</class></catalog>

       </blocks>

</global>

 

 

3> controll文件的修改:

首先

# 控制器不会自动加载,所以我们需要包含文件,这里与区块(Block)不一样

然后extends这个包含的文件。

重写方法。

 

 

4>修改视图文件:

 

<app_shopping_cart_index>

<update handle="checkout_cart_index"/>

</app_shopping_cart_index>

 

    访问shopping/cart/index==checkout/cart/index!

 

 

 

5>重写Magento模型

 

<?xml version="1.0" encoding="UTF-8"?>

<config>

<modules>

<App_Customer>

<version>0.1.0</version>

</App_Customer>

</modules>

 

<global>

<models>

<customer>

<rewrite>

<customer>App_Customer_Model_Customer</customer>

</rewrite>

</customer>

</models>

</global>

</config>

 

 

class App_Customer_Model_Customer extends Mage_Customer_Model_Customer {

// 重写已存在的方法

public function validate() {

// Define new validate rules. From now magento call this validate method instead of existing method

//return $errors;

return true;

}

 

// 你还可以创建新的方法

public function newMethod() {

// function logic

}

}

 

 

 

6>重写Magento的模型资源

<?xml version="1.0" encoding="UTF-8"?>

<config>

<modules>

<App_Customer>

<version>0.1.0</version>

</App_Customer>

</modules>

 

<global>

<models>

<customer>

<rewrite>

<customer>App_Customer_Model_Customer</customer>

<address>App_Customer_Model_Address</address>

</rewrite>

</customer>

<customer_entity>

<rewrite>

<address>App_Customer_Model_Entity_Address</address>

</rewrite>

</customer_entity>

</models>

</global>

</config>

 

class App_Customer_Model_Entity_Address extends Mage_Customer_Model_Entity_Address {

protected function _afterSave(Varien_Object $address) {

// Write your code

}

}

 

 

转载地址:http://ledli.baihongyu.com/

你可能感兴趣的文章
大头小头
查看>>
Oracle 10g Instant Client
查看>>
网页中加入CSS的方法
查看>>
typedef
查看>>
struct
查看>>
原码 补码
查看>>
调用约定与修饰名约定
查看>>
网络号或子网号能否全为1或0
查看>>
GRUB2 控制台分辩率
查看>>
MSXML
查看>>
INondelegationUnknown接口
查看>>
纯小数转换与定点补码
查看>>
Debian Broadcom BCM4313
查看>>
Debian 系统时间
查看>>
COM对象的标识——CLSID
查看>>
COM接口定义和标识
查看>>
接口内存模型
查看>>
C# TextBox中的Validating与Validated事件
查看>>
关于Platform SDK和Windows SDK
查看>>
初始化列表
查看>>