我的自定义模块是支付网关,我有一个重定向 Controller ,这是脚本
class Asurepay_Custompay_AsurepayController extends Mage_Core_Controller_Front_Action {
protected $_order;
public function getOrder() {
if ($this->_order == null) {
}
return $this->_order;
}
public function indexAction(){
echo "index test 1";
}
public function redirectAction(){
$session = Mage::getSingleton('checkout/session');
$session->setAsurepayCustompayQuoteId($session->getQuoteId());
$this->getResponse()->setBody($this->getLayout()->createBlock('asurepay/redirect')->toHtml());
$session->unsQuoteId();
$session->unsRedirectUrl();
}
}
函数redirectAction()无法获取toHtml()函数
这是错误:
Fatal error: Call to a member function toHtml() on a non-object in my code
这应该是什么错误?我在 ModuleName/Block/Redirect.php 中有一个 block ,并且有一个 toHtml()。或者错误的原因是什么?
请求
这是我的重定向 block ,位于 ModuleName/Block/Redirect.php
class Asurepay_Custompay_Block_Standard_Redirect extends Mage_Core_Block_Abstract {
protected function _toHtml() {
$asure = Mage::getModel("custompay/asure");
$form = new Varien_Data_Form();
$form = new Varien_Data_Form();
$form->setAction($standard->getConfig()->getGateurl)
->setId('asurepay_custompay_checkout')
->setName('asurepay_custompay_checkout')
->setMethod('POST')
->setUseContainer(true);
foreach ($standard->getStandardCheckoutFormFields() as $field=>$value) {
$form->addField($field, 'hidden', array('name'=>$field, 'value'=>$value, 'size'=>200));
}
$html = '<html><body>';
$html.= $this->__('You will be redirected to AsurePay in a few seconds.');
$html.= $form->toHtml();
$html.= '<script type="text/javascript">document.getElementById("asurepay_checkout").submit();</script>';
$html.= '</body></html>';
return $html;
}
}
最佳答案
$this->loadLayout();
此时 block 尚未加载。您必须调用加载布局,只有在您才能访问布局中定义的 block 之后。
关于php - magento自定义模块 Controller 无法获取toHtml()函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5855019/