我一直在爲我的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