Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 覆盖Magento触点控制器_Php_Magento_Magento 1.9 - Fatal编程技术网

Php 覆盖Magento触点控制器

Php 覆盖Magento触点控制器,php,magento,magento-1.9,Php,Magento,Magento 1.9,我试图覆盖Mage/Contacts/IndexController.php <?php require_once 'Mage/Contacts/controllers/IndexController.php'; class Mynamespace_CustomContacts_IndexController extends Mage_Contacts_IndexController { protected function indexAction () {

我试图覆盖
Mage/Contacts/IndexController.php

<?php

require_once 'Mage/Contacts/controllers/IndexController.php';

class Mynamespace_CustomContacts_IndexController extends Mage_Contacts_IndexController {

    protected function indexAction () {
        die;
    }
}
我在本地创建了一个文件夹,并创建了
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;
    }
}
我清理了缓存,但是我的死了;不起作用,


感谢所有帮助

完成此操作,它将覆盖
Mage\u联系人中的
IndexController.php

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>

0.1.0
Mynamespace\u自定义联系人
2.不良做法 您可以在
app/local/Mage/Contacts/controllers/IndexController.php
中移动控制器以实现硬覆盖


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

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

我想这里没有

它应该是小写字母,如下所示

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

Mynamespace\u自定义联系人
`
希望这能解决您的问题。

IndexController.php文件(本地/您的公司/您的块名/控制器/

<?php
require_once Mage::getModuleDir('controllers','Mage_Contacts').DS.'IndexController.php';

class IGN_Siteblocks_IndexController extends Mage_Contacts_IndexController
{
    public function indexAction()
    {

    }
}

感谢您的回答,我的XML不完整,我同意并修复了它!我还忘了启用模块,我在app/etc/modules中创建了Mynamespace_CustomContacts.XML,代码如下:
true local
,但它不会改变任何东西。知道我错过了什么吗?再次感谢您r您的时间您的xml文件看起来不错,除了xml声明中的
encoding=“UTF-8”
。请尝试:
true local
<mynamespace_customcontacts before="Mage_Contacts">
     Mynamespace_CustomContacts
</mynamespace_customcontacts>`
<?php
require_once Mage::getModuleDir('controllers','Mage_Contacts').DS.'IndexController.php';

class IGN_Siteblocks_IndexController extends Mage_Contacts_IndexController
{
    public function indexAction()
    {

    }
}
<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');
}
}