覆盖后台的AdminHtml控制器

问题描述 投票:0回答:1

我想覆盖类Mage_Adminhtml_Catalog_CategoryController(Magento后台的类别控制器)。我认为我的config.xml在某处错了,我怀疑<to>标签是问题所在。当我尝试访问http://mywebsite/index.php/admin_k/catalog_category/index/key/somerandomkey/时,我遇到404错误。

我的config.xml:

<?xml version="1.0"?>
<config>
  <modules>
    <Cheek_Lookbook>
      <version>0.0.1</version>
    </Cheek_Lookbook>
  </modules>
  <global>
        <rewrite>        
            <cheek_lookbook_adminhtml_catalog_categorycontroller>
                <from><![CDATA[#^/admin_k/catalog_category/#]]></from> 
                <to>/admin_k/lookbook/adminhtml_catalog_category/</to>
            </cheek_lookbook_adminhtml_catalog_categorycontroller>
        </rewrite>
    <helpers>
      <lookbook>
        <class>Cheek_Lookbook_Helper</class>
      </lookbook>
    </helpers>
        <blocks>
            <lookbook>
                <class>Cheek_Lookbook_Block</class>
            </lookbook>
            <adminhtml>
                <rewrite>
                    <catalog_category_tab_product>Cheek_Lookbook_Block_Adminhtml_Catalog_Category_Tab_Product</catalog_category_tab_product>
                </rewrite>
            </adminhtml>
        </blocks>
        <resources>
            <lookbook_setup>
                <setup>
                    <module>Cheek_Lookbook</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </lookbook_setup>
            <lookbook_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </lookbook_write>
            <lookbook_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </lookbook_read>
        </resources>
  </global>
    <admin>
        <routers>
            <lookbook>
                <use>admin</use>
                <args>
                    <module>Cheek_Lookbook</module>
                    <frontName>admin_lookbook</frontName>
                </args>
            </lookbook>
        </routers>
  </admin>
</config> 

我已经尝试了很多东西(在网址中添加/lookbook/之后的/admin_k,调整<to>中的值...)但我无法弄清楚是什么问题。

在这里,我的控制器类:

<?php
require_once "Mage/Adminhtml/controllers/Catalog/CategoryController.php";  
class Cheek_Lookbook_Adminhtml_Catalog_CategoryController extends Mage_Adminhtml_Catalog_CategoryController {

    public function postDispatch()
    {
        parent::postDispatch();
        Mage::dispatchEvent('controller_action_postdispatch_adminhtml', array('controller_action' => $this));
    }

    public function indexAction() 
    {
        Mage::log('There we aren't', null, 'someRandomLogs.log');
        parent::indexAction();
    }
}

有人有想法吗?

php xml controller override magento-1.9.3
1个回答
0
投票

几天后,我终于明白为什么它不能正常工作。

<rewrite> (...) <from> (...) <to> (...)部分是一种古老的做法。

在Magento 1.9.3中,如果要覆盖adminhtml控制器,则必须执行以下操作:

<?xml version="1.0"?>
<config>
  <modules>
    <Cheek_Lookbook>
      <version>0.0.1</version>
    </Cheek_Lookbook>
  </modules>
  <global>
    (...)
  </global>
    <admin>
        <routers>
            (...)
            <adminhtml>
                    <args>
                        <modules>
                            <Cheek_Lookbook before="Mage_Adminhtml">Cheek_Lookbook_Adminhtml</Cheek_Lookbook>
                        </modules>
                    </args>
            </adminhtml>
        </routers>
  </admin>
</config> 

这是我个人的情况,请找到一个“空”模板来复制下面的粘贴:

<?xml version="1.0"?>
<config>
  <modules>
    <Namespace_Module>
      <version>Your.own.version</version>
    </Namespace_Module>
  </modules>
  <global>
    (...)
  </global>
    <admin>
        <routers>
            (...)
            <adminhtml>
                    <args>
                        <modules>
                            <Namespace_Module before="Mage_Adminhtml">Namespace_Module_Adminhtml</Namespace_Module>
                        </modules>
                    </args>
            </adminhtml>
        </routers>
  </admin>
</config>
© www.soinside.com 2019 - 2024. All rights reserved.