dtiopy6088 2014-05-15 00:02
浏览 30

Magento覆盖后端管理中的扩展控制器

I am kinda in a pickle at the moment kinda tearing my head off. I am trying to override a controller method in the backend admin of Magento to allow some additional functionality. Here is the url path I am trying to apply my override. <Magento root path>/index.php/admin/iBanners_banner/edit/id/2/key/4c9796d89ba5e8847e4ce8c893cd6901/

Here is the admin fragment router xml for the original plugin that is present in their config.xml file.

<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <ibanners before="Mage_Adminhtml">Fishpig_iBanners_Adminhtml</ibanners>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

Here is my controller class with the appropriate edit method that I need to override. This file is located in the following directory structure: app/code/local/Leafcutter/Ibanners/controllers/Adminhtml/Ibanners/BannerController.php

        <?php

    require_once("Fishpig/IBanners/controllers/Adminhtml/IBanners/BannerController.php");
    class Leafcutter_iBanners_Adminhtml_iBanners_BannerController extends Fishpig_iBanners_Adminhtml_iBanners_BannerController
    {
        public function _construct(){
            Mage::log('Using Leafcutter Extension');
            parent::_construct();
        }
        public function editAction()
        {
            die('Leafcurtter has been returned');
        }
}

As you would expect if you go to this edit url, my modified edit function should die with a message.

I also apply the what I thought were the appropriate bits of code for the admin fragment router xml in my extension's config.xml file. Now when I refresh the page or I log out and log back into to the backend. My extension's controller does not override the original controller and the original controller loads as if my version did not exist at all.

The following 2 fragments were sample of what I have attempted to override the original extension's controller both did not work but are an example of all of the unsuccessful attempts at getting this to work.

<admin>
            <routers>
                <adminhtml>
                    <args>
                        <modules>
                            <ibanners before="Mage_Adminhtml">Leafcutter_iBanners_Adminhtml</ibanners>
                        </modules>
                    </args>
                </adminhtml>
            </routers>
        </admin>

        <admin>
            <routers>
                <ibanners>
                    <args>
                        <modules>
                            <Leafcutter_iBanners before="Fishpig_iBanners">Leafcutter_iBanners_Adminhtml</Leafcutter_iBanners>
                        </modules>
                    </args>
                </ibanners>
            </routers>
        </admin>

Unless if strictly it is impossible to override an extension's backend controller at all and my solution was flawed from the start, if someone can help me especially looking at my admin router code in my config xml then that would be great. Because I don't want to apply a hack to the original extension, which I may have to do if presented with absolutely no choice. Thanks in advance.

  • 写回答

2条回答 默认 最新

  • dongxinm279890 2014-05-15 01:28
    关注

    Override is probably the wrong word to use for replacing a controller class. It's better to think of these sorts of configurations as something like "adding a module's controllers as options for a particular URL route" With that in mind, there's X reasons this could go wrong.

    1. Your configuration is wrong/incorrect

    2. Magento finds a controller in the Fishpig module first.

    3. Magento finds your configuration, but can't find a controller that's named correctly

    The _validateControllerClassName method in app/code/core/Mage/Core/Controller/Varien/Router/Standard.php is a great place to start debugging these sorts of things. Some var_dump debugging in there will tell you why Magento accepted or rejected a particular module's controller configuration (or if it never found it in the first place)

    评论

报告相同问题?

悬赏问题

  • ¥15 我的数据无法存进链表里
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端