VCPHP网站模板 - 外贸网站建设,外贸网站模板

VCPHP网站模板

当前位置: 首页 > Magento > Magento教程 >

magento模块重写

时间:2014-06-21 12:58来源:未知 作者:VCPHP网站模板 点击:
以重写 app/code/core/Mage/Catalog/Block/Navigation.php 为例 1. 复制Mage ( 不推荐使用 ) First add a new Navigation.php file you can edit to your local folder that Magento will reference instead of the original. Copy the original

以重写 app/code/core/Mage/Catalog/Block/Navigation.php 为例

 

1. 复制Mage (不推荐使用 )

 

First add a new Navigation.php file you can edit to your local folder that Magento will reference instead of the original.

 

Copy the original found here:  app/code/core/Mage/Catalog/Block/Navigation.php

Recreate this folder structure in your app/code/local folder. So go to app/code/local, make a Mage folder, inside it make a Catalog folder, inside that make a Block folder, and inside that place your copy of Navigation.php, eg:  app/code/local/Mage/Catalog/Block/Navigation.php

 

Second, add some code to the app/etc/local.xml file, inside of the global tags.

Xml代码  收藏代码
  1. <blocks>   
  2.     <catalog>  
  3.         <rewrite>  
  4.             <navigation>Mage_Catalog_Block_Navigation</navigation>                  
  5.         </rewrite>  
  6.     </catalog>  
  7. </blocks>   
 

2. 重写 (推荐 )

 

If you want to override a core controller on Magento in order to add other customActions, it is really quick and easy to do so. Here are the files that you have to take into account:

  • The block you want to override : /app/code/core/Mage/Catalog/Block/Navigation.php
  • The xml file to enable the module: /app/etc/modules/[namespace] _All.xml
  • The block xml file definition : /app/code/local/[namespace] /Catalog/etc/config.xml
  • The overridden block : /app/code/local/[namespace] /Catalog/Block/Navigation.php

本文中所有 [namespace] 将被取代为我自己实例的名称 “App”,如果你想要用其他命名空间,可以替换[namespace]

 

First of all, you have to enable the module on the /app/etc/modules/ directory. This file would be App _All.xml and inside that:  

Xml代码  收藏代码
  1. <?xml version="1.0"?>  
  2. <config>  
  3.      <modules>  
  4.         <App_Catalog>  
  5.             <active>true</active>  
  6.             <codePool>local</codePool>  
  7.             <!--depends>  
  8.                 <Mage_Core/>  
  9.             </depends-->  
  10.         </App_Catalog>  
  11.      </modules>  
  12. </config>  
 

开启depends的话,表示依靠core class, 

 

Now it’s time to create the /app/code/local/App /Catalog/etc/config.xml file that will override the core block:

Xml代码  收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <config>  
  3.     <modules>  
  4.         <App_Catalog>  
  5.             <version>0.1.0</version>  
  6.         </App_Catalog>  
  7.     </modules>  
  8.     <global>  
  9.         <blocks>  
  10.             <catalog>  
  11.                 <rewrite>  
  12.                         <navigation>App_Catalog_Block_Navigation</navigation>  
  13.                 </rewrite>  
  14.             </catalog>  
  15.         </blocks>  
  16.     </global>  
  17. </config>  

 

注意:<navigation>App_Catalog_Block_Navigation</navigation> 中 App_Catalog_Block_Navigation 不能随便起名,一定要形成正确完整的路径, [namespace] _Catalog_Block_Navigation =>[namespace]/Catalog/Block/Navigation.php

 

Finally, we can create the class that will add/change actions to the core block:app/code/local/App/Catalog/Block/Navigation.php

Java代码  收藏代码
  1. <?php  
  2. class App_Catalog_Block_Navigation extends Mage_Catalog_Block_Navigation  
  3. {  
  4.     protected function _renderCategoryMenuItemHtml($category, $level = 0, $isLast = false, $isFirst = false,  
  5.         $isOutermost = false, $outermostItemClass = '', $childrenWrapClass = '', $noEventAttributes = false, $showText = false)  
  6.     {  
  7.        /* .... */  
  8.     }  
  9. }  
 

注意: class是继承了原来的Mage_Catalog_Block_Navigation

 

注意:如果要看效果,要清理cache先,或者在后台 disable cache

(责任编辑:VCPHP网站模板)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
验证码: 点击我更换图片
栏目列表
推荐内容
 
QQ在线咨询
售前电话热线
400-083-8184
售前QQ客服