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