我对 Mage_Core_Controller_Request_Http 做了一些更改,但在使用 magento 分发的文件中。我知道这不是最好的方法,但我无法弄清楚如何覆盖控制器目录中的文件。我可以找到如何覆盖控制器目录中的文件。
谁能告诉我如何在我自己的扩展中覆盖 Mage_Core_Controller_Request_Http 。
thanks
如果您不想恢复到包含路径黑客,您还可以使用反射在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 代码池复制完整的类。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)