本文介紹了覆蓋 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 聯系人控制器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!