这不是扩展控制器的推荐方式。我将假设您要扩展 Checkout OnepageController。
这样做的正确方法是。
1.) 识别正确的模块或为此创建一个新模块。
app/code/local/Mel/Gallosa(记得在 app/etc/modules 中激活模块)
添加文件 etc/config.xml 和 controllers/OnepageController.php
您的文件内容将是
<?xml version="1.0"?>
<config>
<modules>
<Mel_Gallosa>
<version>0.1.0</version>
</Mel_Gallosa>
</modules>
<frontend>
<routers>
<checkout>
<use>standard</use>
<args>
<modules>
<Mel_Gallosa before="Mage_Checkout">Mel_Gallosa</Mel_Gallosa>
</modules>
</args>
</checkout>
</routers>
</frontend>
</config>
然后你的新控制器文件
<?php
require_once 'Mage/Checkout/controllers/OnepageController.php';
class Mel_Gallosa_OnepageController extends Mage_Checkout_OnepageController
{
/*you can now overide any method here. Remember that you want to extend code in an Object Orientated fashion. Call the parent functions when appropriate and at the right time. Only replace methods that you are trying to overwrite. There is no need to dump all methods here. */
//here is an example
public function indexAction()
{
Mage::log('we have now overwritten the index action',null,'mel.log');
parent::indexAction(); /* this means that if there are any core updates you will get them too :) */
}
}
就是这样。我的建议不是简单地复制文件夹。清楚地考虑你正在尝试做什么,并确保你以后不要做“可能会击中你的脚”的事情。保持 OO 完好无损!