在后台覆盖 AdminHtml 控制器
Override an AdminHtml controller in back-office
我想覆盖 class 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>
我尝试了很多东西(在 URL 中的 /admin_k
之后添加 /lookbook/
,调整 <to>
中的值 ...)但是我不知道怎么回事。
在这里,我的控制器class:
<?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();
}
}
有人知道吗?
几天后,我终于明白为什么它不能正常工作了。
<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>
那是我个人的情况,请在下面找到一个 "empty" 模板复制过去 :
<?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>
我想覆盖 class 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>
我尝试了很多东西(在 URL 中的 /admin_k
之后添加 /lookbook/
,调整 <to>
中的值 ...)但是我不知道怎么回事。
在这里,我的控制器class:
<?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();
}
}
有人知道吗?
几天后,我终于明白为什么它不能正常工作了。
<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>
那是我个人的情况,请在下面找到一个 "empty" 模板复制过去 :
<?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>