2015-09-04 105 views
2

我需要作出改變Magento的功能_checkBaseUrl內發現:Magento的 - 如何擴展前端控制器

app/code/core/Mage/Core/Controller/Varien/Front.php 

作爲最佳實踐我想這與我自己的模塊擴展,所以我不能編輯核心代碼和文件,但它不工作。如果我在覈心文件中進行更改,我會得到所需的響應,但在使用此文件時不起作用。我的模塊被顯示爲在Configuration > Advanced > Advanced

文件啓用爲如下:

等/模塊/ Me_Coreextend.xml

<?xml version="1.0" encoding="UTF-8"?> 
<config> 
    <modules> 
     <Me_Coreextend> 
      <active>true</active> 
      <codePool>local</codePool> 
     </Me_Coreextend> 
    </modules> 
</config> 

應用程序/代碼/本地/ ME/Coreextend /等/config.xml

<?xml version="1.0"?> 
<config> 
    <modules> 
     <Me_Coreextend> 
      <version>1.0</version> 
     </Me_Coreextend> 
    </modules> 
    <frontend> 
     <routers> 
      <core> 
       <args> 
        <modules> 
         <Me_Coreextend before="Mage_Core">Me_Coreextend</Me_Coreextend> 
        </modules> 
       </args> 
      </core> 
     </routers> 
    </frontend> 
</config> 

應用程序/代碼/本地/ ME /有限公司reextend/Controller/Varien/Front.php

我在此文件中只包含_checkBaseUrl函數而不是全部內容app/code/core/Mage/Core/Controller/Varien/Front.php - 這是正確的嗎? (我試圖包括它,但仍然不起作用)

include_once('Mage/Core/Controller/Varien/Front.php'); 
class Me_Coreextend_Controller_Varien_Front extends Mage_Core_Controller_Varien_Front 
{ 
    protected function _checkBaseUrl($request) 
    { 
     // custom changes... 
    } 
} 

有什麼我做錯了嗎?

回答

2

不能擴展Magento的前端控制器,因爲不是一個「標準」的服務控制器(請注意,是在Controller文件夾,而不是在一個controllers )。

$this->_frontController = new Mage_Core_Controller_Varien_Front(); 

你只能在你的項目中的本地文件夾中的文件複製:如您在Mage_Core_Model_App類由run方法稱爲_initFrontController方法參見

app/code/local/Mage/Core/Controller/Varien/Front.php

,安全地根據編輯的文件您的業​​務需求。

0

的Magento沒有提供對文件夾的「控制器」覆蓋控制文件的功能,你只能覆蓋這是在「控制器」文件夾控制器文件

簡單,你只需複製你的文件來加載

應用程序/代碼/本地/法師/核心/控制器/瓦瑞恩/ Front.php