覆盖Magento联系人控制器


Override Magento Contacts Controller

我正在尝试覆盖Mage/Contacts/IndexController.php

我在本地创建了一个文件夹并创建了Mynamespace/CustomContacts/controllers/IndexController.php

<?php
require_once 'Mage/Contacts/controllers/IndexController.php';
class Mynamespace_CustomContacts_IndexController extends Mage_Contacts_IndexController {
    protected function indexAction () {
        die;
    }
}

我也把这个代码放在Mynamespace/CustomContacts/etc/config.xml

<config>
    <frontend>
        <routers>
            <contacts>
                <args>
                     <modules>
                        <Mynamespace_CustomContacts before="Mage_Contacts">Mynamespace_CustomContacts</Mynamespace_CustomContacts>
                    </modules>
                </args>
            </contacts>
        </routers>
    </frontend>
</config>

我清理了缓存,但是我死了;不工作,

感谢您的帮助

最佳实践

您的config.xml文件看起来像这样:

<?xml version="1.0"?>
<config>
    <modules>
        <Mynamespace_CustomContacts>
            <version>0.1.0</version>
        </Mynamespace_CustomContacts>
    </modules>
    <frontend>
        <routers>
            <contacts>
                <args>
                    <modules>
                        <Mynamespace_CustomContacts before="Mage_Contacts">Mynamespace_CustomContacts</Mynamespace_CustomContacts>
                    </modules>
                </args>
            </contacts>
        </routers>
    </frontend>
</config>

2。不好的实践

您可以在app/local/Mage/Contacts/controllers/IndexController.php中移动控制器以进行硬覆盖。

不要忘记在app/etc/modules目录下的xml文件中启用你的模块

通过这个,它从Mage_Contacts覆盖IndexController.phphttp://www.amitbera.com/how-to-override-a-controller-in-magento/

IndexController.php文件(local/your_company/your_block_name/controllers/

<?php
require_once Mage::getModuleDir('controllers','Mage_Contacts').DS.'IndexController.php';
class IGN_Siteblocks_IndexController extends Mage_Contacts_IndexController
{
    public function indexAction()
    {
    }
}

本地/your_company/your_block_name/etc/config . xml

<contacts>
                <args>
                    <modules>
                        <siteblocks before="Mage_Contacts">IGN_Siteblocks</siteblocks>
                    </modules>
                </args>
            </contacts>

让我们像这样创建示例代码:

class IGN_Siteblocks_IndexController extends Mage_Contacts_IndexController
{
   public function createAction()
{
    return $this->_redirect('noroute');
}
}

在得到答案之前,我想知道必须在config.xml文件中定义您的自定义模块。

我认为这里缺少了这一点。

添加
<modules>
        <Mynamespace_CustomContacts>
            <version>1.0.0</version>
        </Mynamespace_CustomContacts>
    </modules>

config.xml文件中config节点后面。

<Mynamespace_CustomContacts before="Mage_Contacts">
    Mynamespace_CustomContacts
</Mynamespace_CustomContacts>`

应该是像下面这样的小字母

<mynamespace_customcontacts before="Mage_Contacts">
     Mynamespace_CustomContacts
</mynamespace_customcontacts>`