加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Magento 1.7 – 如何扩展核心控制器

发布时间:2020-12-13 22:45:22 所属栏目:PHP教程 来源:网络整理
导读:我正在尝试使用此设置扩展OnepageController: 应用程序的/ etc /模块/ Custom_Checkout.xml config modules Custom_Checkout activetrue/active codePoollocal/codePool /Custom_Checkout /modules/config 应用程序/本地/自定义/结帐的/ etc / config.xml中
我正在尝试使用此设置扩展OnepageController:

应用程序的/ etc /模块/ 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>

应用程序/本地/自定义/结帐/控制器/ OnepageController.php

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

class Custom_Checkout_OnepageController extends Mage_Checkout_OnepageController
{

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

}

我见过这些:
Extend magento core controller (Checkout/OnepageController)

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

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

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

解决方法

遗憾的是,这里可能存在许多错误,而且您的帖子中没有足够的信息来跟踪它们.这是一个调试技巧,而不是答案.看一下_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;
}

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读