覆盖 Magento 联系人控制器

2021-12-19 00:00:00 php magento magento-1.9

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

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

I created a folder in local and created 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>

我清理了缓存,但我死了;不起作用,

I cleaned the cache, but my die; does not work,

感谢您的帮助

推荐答案

1.最佳做法

你的 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 中移动控制器以进行硬覆盖.

2. Bad practices

You can move your controller in app/local/Mage/Contacts/controllers/IndexController.php for a hard override.

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

相关文章