Magento的block重写规则

来源:互联网 发布:数控铣床编程格式 编辑:程序博客网 时间:2024/06/09 23:01

Magento的block重写规则帮助和模型覆盖相似。 Magento的遵循MVC模式,但在Magento块是额外的一层块类特定模板呈现数据 Magento的介绍伟大的模板设计系统block制度。

块是一个途径,使Magento的区分系统中的功能阵列,并创建一个模块化的方式来管理,从视觉和功能的观点来看它。magento有两种类型的块,他们共同创造的视觉输出。

* Structural Blocks

 

* Content Blocks

 

Magento通过模板的模板页面的内容收集整理,全(X)HTML的输出.

如何覆盖

在这里,我用客户为例模块。这里我描述了各种客户为例块类覆盖系统。

a)客户登记表块(Mage_Customer_Block_Form_Register
b)客户视图的形式块(Mage_Customer_Block_Form_View
c)客户的地址编辑块(Mage_Customer_Block_Address_Edit
d)客户帐户控制面板信息块Mage_Customer_Block_Account_Dashboard_Info
e)客户帐户控制面板地址块(Mage_Customer_Block_Account_Dashboard_Address
六)客户部件名称块(Mage_Customer_Block_Widget_Name

 

1。第一次创建新的模块来处理下面的代码重写工作,并写在app/etc/modules/Yt_Customer.xml

 

<?xml version="1.0"?>
<config>
<modules>
<Yt_Customer>
<active>true</active>
<codePool>local</codePool>
</Yt_Customer>
</modules>
</config>

2。配置app/code/local/Yt/Customer/etc/config.xml在这里,我5 / 6为例覆盖语法。只保留这些类例子,你需要重写

<?xml version="1.0"?>
<config>
<modules>
<Yt_Customer>
<version>0.1.0</version>
</Yt_Customer>
</modules>

<global>
<blocks>
<customer>
<rewrite>
<form_register>Yt_Customer_Block_Form_Register</form_register>
<form_view>Yt_Customer_Block_Form_View</form_view>
<address_edit>Yt_Customer_Block_Address_Edit</address_edit>
<account_dashboard_address>Yt_Customer_Block_Account_Dashboard_Address</account_dashboard_address>
<account_dashboard_info>Yt_Customer_Block_Account_Dashboard_Info</account_dashboard_info>
<widget_addressname>Yt_Customer_Block_Widget_Name</widget_addressname>
</rewrite>
</customer>
</blocks>
</global>
</config>


3。现在,你的新块类并定义所有覆盖方法
a) Customer register form block override
class Yt_Customer_Block_Form_View extends Mage_Customer_Block_Account_Dashboard
{
// override existing method
//write new function
public function newmethod()
{
return true;
}
}
b) Customer view form block (Mage_Customer_Block_Form_View)
class Yt_Customer_Block_Form_View extends Mage_Customer_Block_Account_Dashboard
{
// override existing method
//write new function
public function newmethod()
{
return true;
}
}
c) Customer address edit block
class Yt_Customer_Block_Address_Edit extends Mage_Customer_Block_Address_Edit
{
// override existing method
public function getAddressStatus()
{
return $this->getRequest()->getParam('address');
}

//write new function
public function newmethod()
{
return true;
}
}
.......