【发布时间】:2014-06-22 18:19:49
【问题描述】:
我尝试从 Magento 重写核心文件。但是改写块后就无法访问了,不知道为什么?
我尝试重写的文件是:Mage_Paypal_Block_Standard_Redirect
xml 配置(位于:app/local/Ga/etc/config.xml):
<global>
<models>
<ga>
<class>Ga_Model</class>
</ga>
</models>
<blocks>
<ga>
<class>Ga_Block</class>
</ga>
<paypal>
<rewrite>
<standard_redirect>
Ga_Block_Paypal_Standard_Redirect
</standard_redirect>
</rewrite>
</paypal>
</blocks>
<helpers>
<ga>
<class>Ga_Helper</class>
</ga>
</helpers>
</global>
自定义块(位于:app/local/Ga/Block/Paypal/Standard/Redirect.php):
class Ga_Block_Paypal_Standard_Redirect extends Mage_Paypal_Block_Standard_Redirect {
protected function _toHtml()
{
return 'test';
}
}
Paypal 控制器这样调用块:
public function redirectAction()
{
$session = Mage::getSingleton('checkout/session');
$session->setPaypalStandardQuoteId($session->getQuoteId());
$this->getResponse()->setBody($this->getLayout()->createBlock('paypal/standard_redirect')->toHtml());
$session->unsQuoteId();
$session->unsRedirectUrl();
}
"createBlock" 方法重写后不返回任何内容。
我不知道我做错了什么。
谢谢
编辑: 我找到了解决方案。问题来自这样一个事实,即有必要像这样在一行中编写自定义块类:
<blocks>
<ga>
<class>Ga_Block</class>
</ga>
<paypal>
<rewrite>
<standard_redirect>Ga_Block_Paypal_Standard_Redirect</standard_redirect>
</rewrite>
</paypal>
</blocks>
【问题讨论】: