Sunday, March 18, 2012

Magento的block重写规则


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 blockclass 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;
}
}

No comments:

Post a Comment