4

我正在尝试使用此设置扩展 OnepageController:

应用程序/etc/modules/Custom_Checkout.xml

<config>
    <modules>
        <Custom_Checkout>
            <active>true</active>
            <codePool>local</codePool>
        </Custom_Checkout>
    </modules>
</config>

应用程序/本地/自定义/结帐/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Custom_Checkout>
            <version>0.0.1</version>
        </Custom_Checkout>
    </modules>
    <frontend>
        <routers>
            <checkout>
                <args>
                    <modules>
                        <custom_checkout before="Mage_Checkout">Custom_Checkout</custom_checkout>
                    </modules>
                </args>
            </checkout>
        </routers>
    </frontend>
</config>

app/local/Custom/Checkout/controllers/OnepageController.php

require_once("Mage/Checkout/controllers/OnepageController.php");

class Custom_Checkout_OnepageController extends Mage_Checkout_OnepageController
{

    public function indexAction()
    {
    echo "Index overidden";
    }

}

我见过这些: 扩展 magento 核心控制器 (Checkout/OnepageController)

http://www.magentocommerce.com/wiki/5__-_modules_and_development/0__-_module_development_in_magento/how_to_overload_a_controller

加上一些我无法发布的内容,但上述方法似乎都不起作用。它只是不会覆盖控制器。

关于为什么这不被覆盖的任何想法?

4

2 回答 2

1

不幸的是,这里有无数可能出错的地方,并且您的帖子中没有足够的信息来追踪它们。这是一个调试技巧,而不是答案。看一下_validateControllerClassName功能。

protected function _validateControllerClassName($realModule, $controller)
{
    $controllerFileName = $this->getControllerFileName($realModule, $controller);
    if (!$this->validateControllerFileName($controllerFileName)) {
        return false;
    }

    $controllerClassName = $this->getControllerClassName($realModule, $controller);
    if (!$controllerClassName) {
        return false;
    }

    // include controller file if needed
    if (!$this->_includeControllerClass($controllerFileName, $controllerClassName)) {
        return false;
    }

    return $controllerClassName;
}

每个return false状态都是 Magento 可能决定不使用您的控制器类进行请求的状态。尝试在 if 语句的内部和外部添加一些日志记录var_dump或, $controllerFileName$controllerClassName这通常足以指出文件路径名或类中的小错误(大小写、缺少字符等)来确定您的模块。

如果你没有看到任何与 相关的信息Custom_Checkout,这意味着 Magento 看不到你的模块,你应该开始调试它。

于 2013-04-27T22:53:34.267 回答
0

我认为解决方案是有正确的案例。代替:

<custom_checkout before="Mage_Checkout">Custom_Checkout</custom_checkout>

它应该拼写:

<Custom_Checkout before="Mage_Checkout">Custom_Checkout</Custom_Checkout>
于 2013-04-27T20:08:22.727 回答