在上一篇文章里, 我们着重介绍了对magento常规的model, block和controller的重构, 其中model和block类的重载都比较简单,直接复制一个,按照相同的目录格式放到local下就可以了, 但是如果对controller和config文件进行重构就要麻烦些了.
今天介绍一种针对adminhtml的controller的简单重构方法,假设我们需要针对report扩展一种新的报表, 那么我们需要正对report的controller进行重构:
1. 先创建自己的module,parkage的名字定为Matrix,模块为Report. 该模块的目录结构应该为如下结构:
/app/code/local/Matrix/Report/controllers/
/app/code/local/Matrix/Report/etc/
/app/code/local/Matrix/Report/Block/
/app/code/local/Matrix/Report/Helper/
/app/code/local/Matrix/Report/Model/
/app/code/local/Matrix/Report/sql/
2. 在app/etc/Modules里添加一个module的配置文件Matrix_Report.xml
|
1
2
3
4
5
6
7
8
9
|
<?xml version="1.0"?><config> <modules> <Matrix_Report> <active>true</active> <codePool>local</codePool> </Matrix_Report> </modules></config> |
3. 在/app/code/local/Matrix/Report/etc/config.xml里面添加下面的关键代码:
|
1
2
3
4
5
6
7
8
9
10
11
12
|
<admin> <routers> <adminhtml> <args> <modules> <Matrix_Report before="Mage_Adminhtml">Matrix_Report</Matrix_Report> </modules> <frontName>report</frontName> </args> </adminhtml> </routers></admin> |
4. 最后, 我们就可以对我们想重构的controller进行重构了:
include(“Mage/Adminhtml/controllers/Report/ SalesController.php”);
class Matrix_Report _OrderController extends Mage_Adminhtml_Report_SalesController
{
}
怎么样, 这种方式很直观明了吧, 其实,我们还可以用这种方式对magento后台进行功能扩展, 自定义layout.xml等等相关操作….
好吧, 今天就到这里吧, 下次, 我们将总结一下, 如果需要针对已经重构的module再进行第二次重构,该怎么做?

