我需要对 Magento 函数 _checkBaseUrl
进行更改:
app/code/core/Mage/Core/Controller/Varien/Front.php
作为最佳实践,我尝试使用自己的模块扩展它,因此我没有编辑核心代码和文件,但它不起作用。如果我在核心文件中进行更改,我会得到所需的响应,但在使用它时它不起作用。我的模块在配置>高级>高级
文件如下:
etc/modules/Me_Coreextend.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Me_Coreextend>
<active>true</active>
<codePool>local</codePool>
</Me_Coreextend>
</modules>
</config>
app/code/local/Me/Coreextend/etc/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>
app/code/local/Me/Coreextend/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...
}
}
我是不是做错了什么?
最佳答案
您无法扩展 Magento 的前端 Controller ,因为它不是“标准”服务 Controller (请注意,它位于 Controller
文件夹中,而不是 controllers
文件夹中)。正如您在 _initFrontController
方法中的 Mage_Core_Model_App
类中看到的,由 run
方法调用:
$this->_frontController = new Mage_Core_Controller_Varien_Front();
您只能复制项目本地文件夹中的文件:
app/code/local/Mage/Core/Controller/Varien/Front.php
并根据您的业务需求安全地编辑文件。
关于Magento - 如何扩展前端 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32395210/