我一直在为我的Magento模块在adminhtml中获取新表单。然而,我遇到了实际加载块的严重问题。我可以加载一个试块(使用PHTML布局)使用此代码,我在不同的堆栈溢出的问题发现(我在adminhtml控制器实现此):在Magento中实例化(而不是一个对象)之后,什么原因导致一个块为假?
$block = $this->getLayout()->createBlock('coupsmart_coupon/adminhtml_forms');
error_log('The block:' . var_export($block, true));
if($block)
{
$block->setTemplate('test/test.phtml');
error_log(var_export($block->getTemplate(), true));
error_log('The HTML:');
error_log(var_export($block->toHtml(),true));
}
使用试块,我找回正确的html(在我的adminhtml/default/default/template文件夹中找到)。
但是,当我实例化一个grid_container块时,它不运行if($block){}
部分,因为该块为假。但是在我的grid_container的block类中,我有一个__constructor()
方法,它记录了一个输出,所以它运行构造函数,这意味着我的类实例化(和命名)是正确的。
什么会导致构造函数在块上运行,但它仍然返回false,对于Mage_Adminhtml_Block_Widget_Grid_Container
类?
如果需要更多的代码(控制器,grid_container块,网格块,配置等)是必要的,让我知道了,我会后它。我只是不想用可能淡化问题的代码溢出来淹没。
编辑:网格集装箱
class Coupsmart_Coupon_Block_Adminhtml_Forms extends
Mage_Adminhtml_Block_Widget_Grid_Container
{
public function __construct()
{
error_log('adminhtml forms (parent) construct');
$this->_controller = 'adminhtml_forms';
$this->_blockGroup = 'coupsmart_coupon';
$this->_headerText = Mage::helper('forms')->__('Coupon Manager');
$this->_addButtonLabel = Mage::helper('forms')->__('Edit Coupon');
parent::__construct();
}
}
上述错误日志中的容器时显示我实例化块。如果在它实例化一个异常被抛出
你是我的救命恩人。非常感谢你。 – rastafarianmenagerie 2012-07-18 17:33:44