Magento模型的重写规则
来源:互联网 发布:手机mac修改软件 编辑:程序博客网 时间:2024/04/28 17:58
使用Magento的重写规则,你可以很容易扩展Magento的功能或任何可以添加新的模块。 Magento的遵循MVC模式。模型是MVC的主要形式之一。模型通常用于数据库连接和各种逻辑编码。 Mogento也使用同样的目的模型。每一个模块有自己的Magento的模型类。但你可以扩展或修改以下的Magento重写规则的任何现有的模型类。
假设,以满足您的项目要求,您需要更改或提高客户的模型类。您可以更改Mage_CUstomer_Model_Customer类的代码。但它不是一个好的做法的Magento定制和Magento版本升级时,那么有一个删除您的自定义代码的机会。意味着你将失去你的变化。实际上它会为你可怜!!!!!因此,我们应该遵循的Magento重写规则。在这里,我想清楚如何轻松地覆盖你的各种模型类。
Override Customer Model class:
在第一次创建新的模块做下面的代码重写工作,并写在app/etc/modules/Yt_Customer.xml
<?xml version="1.0"?>
<config>
<modules>
<Yt_Customer>
<active>true</active>
<codePool>local</codePool>
</Yt_Customer>
</modules>
</config>
做好app/code/local/Yt/Customer/etc/config.xml配置
<?xml version="1.0"?>
<config>
<modules>
<Yt_Customer>
<version>0.1.0</version>
</Yt_Customer>
</modules>
<global>
<models>
<customer>
<rewrite>
<customer>Yt_Customer_Model_Customer</customer>
</rewrite>
</customer>
</models>
</global>
</config>
现在,写你的新模型类Yt_Customer_Model_Cutomer并定义所有覆盖的方法
class Yt_Customer_Model_Customer extends Mage_Customer_Model_Customer
{
// override existing method
public function validate()
{
// Define new validate rules. From now magento call this validate method instead of existing method
//return $errors;
return true;
}
// You can create new method as you needed.
public function newMethod()
{
// function logic
}
}
如下面这样定义app/code/Yt/Customer/etc/config.xml。在这里,您将获得更清晰的概念如何覆盖各种型号相同的XML类
<?xml version="1.0"?>
<config>
<modules>
<Yt_Customer>
<version>0.1.0</version>
</Yt_Customer>
</modules>
<global>
<models>
<customer>
<rewrite>
<customer>Yt_Customer_Model_Customer</customer>
<address>Yt_Customer_Model_Address</address>
</rewrite>
</customer>
<customer_entity>
<rewrite>
<address>Yt_Customer_Model_Entity_Address</address>
</rewrite>
</customer_entity>
</models>
</global>
</config>
- Magento模型的重写规则
- Magento的helper重写规则
- Magento的block重写规则
- Magento控制器、块、模型的重写
- Magento的URL重写问题
- Magento的URL重写问题
- magento的eav模型
- 方法重写的规则
- .htaccess -------------的重写规则,
- .htaccess的重写规则
- .htaccess的重写规则
- YII的重写规则
- Java重写的规则
- Magento的控制器改写规则
- magento模块 -重写某个magento模块的某个controller
- 重写某个magento模块的某个controller
- 重写magento的model, block 和controller
- 重写magento的model, block 和controller
- Convirture 被管理端机器KVM解决方案的依赖的软件列表
- 说说高通和低通的相互关系(磨皮锐化技术准探讨)
- android SAX解析XML
- SQL Server数据导入导出的几种方法
- 针对SharePoint代码的优化和检查方案
- Magento模型的重写规则
- 周六羽毛球
- 新手必读“嵌入式系统学习11大步骤”
- 讲述C# List排序用法的小细节
- Word管理论文的参考文献
- 世间本如此
- start_kernel->setup_arch->paging_init-->free_area_init_node 之 1
- C语言链表
- 四道经典C语言指针试题