Override Magento Contacts Controller(覆盖 Magento 联系人控制器)
问题描述
我正在尝试覆盖 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 文件中启用您的模块
这篇关于覆盖 Magento 联系人控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:覆盖 Magento 联系人控制器
基础教程推荐
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
