我对 Mage_Core_Controller_Request_Http 进行了一些更改,但在 magento 分发的文件中。这不是最好的方法,我知道,但我一直无法弄清楚如何覆盖 Controller 目录中的文件。我可以找出如何覆盖 Controller 目录中的文件。
谁能告诉我如何在我自己的扩展中覆盖 Mage_Core_Controller_Request_Http。
谢谢
最佳答案
如果您不想恢复到包含路径 hack,您还可以使用反射在 Mage_Core_Model_App
模型上设置您自己的请求类。您可以为此使用 controller_front_init_before
事件的观察者。
我假设您熟悉如何创建事件观察器,所以我将只添加观察器方法的代码。如果您需要更多信息,请询问。
// Observer method
public function controllerFrontInitBefore(Varien_Event_Observer $observer)
{
$app = Mage::app();
$reflection = new ReflectionClass($app);
$property = $reflection->getProperty('_request');
$property->setAccessible(true);
$myRequest = new Your_Module_Controller_Request_Http();
$myRequest->setOrigRequest($app->getRequest()); // if needed
$property->setValue($app, $myRequest);
// Proof of concept:
// Loggs Your_Module_Controller_Request_Http
Mage::log(get_class(Mage::app()->getRequest()));
}
创建类 Your_Module_Controller_Request_Http
并扩展原始的 Mage_Core_Controller_Request_Http
。
在那次事件之后,您的请求对象将被使用而不是原来的。
这使您能够尽可能保持升级安全,因为您不必从 cor 代码池中复制整个类。
关于magento - 我如何覆盖 Mage_Core_Controller_Request_Http,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9199854/