0

我一直在为我的 Magento 模块在 adminhtml 中获取一个新表单。然而,我在实际加载块时遇到了一个严重的问题。我可以使用我在另一个堆栈溢出问题中找到的这段代码加载一个测试块(使用 phtml 布局)(我在 adminhtml 控制器中实现了这个):

    $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 块类中,我有一个__constructor()记录输出的方法,因此它正在运行构造函数,这意味着我的类实例化(和命名)是正确的。

什么会导致构造函数在块上运行,但对于一个Mage_Adminhtml_Block_Widget_Grid_Container类,它仍然返回 false?

如果需要更多代码(控制器、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();
    }
}

当我实例化块时,会显示上面容器中的错误日志。

4

1 回答 1

2

The returned block can be false if an exception is thrown while it's instantiated. In your code, this may certainly come from this part : Mage::helper('forms').
In the config.xml file of your module, have you defined the helpers like this ? :

<global>
    <helpers>
        <forms><class>Coupsmart_Coupon_Helper</class></forms>
    </helpers>
</global>

Else, replace forms by the other code you used in the calls to Mage::helper('forms') (from what it seems, this should probably rather looks like this : Mage::helper('coupsmart_coupon'))

于 2012-07-18T17:25:09.203 回答