以重写 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.
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:
本文中所有 [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:
开启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:
注意:<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
注意: class是继承了原来的Mage_Catalog_Block_Navigation
注意:如果要看效果,要清理cache先,或者在后台 disable cache (责任编辑:最模板) |