単に、新しい編集タブを追加した後、MagentoのProduct Adminにこのエラーが表示されます。Magento - 非オブジェクト上のメンバー関数createBlock()を呼び出す
Fatal error: Call to a member function createBlock() on a non-object in
/var/www/app/code/local/RedoxStudios/ErpTab/Block/Adminhtml/Catalog/Product/Tab.php
on line 11
私は私のコードでこれを持っている:
<?php
class RedoxStudios_ErpTab_Block_Adminhtml_Catalog_Product_Tab
extends Mage_Adminhtml_Block_Template
implements Mage_Adminhtml_Block_Widget_Tab_Interface {
/*
* Set the template for the block
*/
public function __construct() {
parent::__construct();
$this->getLayout()->createBlock('Purchase/Product_Widget_StockDetails_Summary');
$this->setProduct($this->getProduct());
$this->setTemplate('Purchase/Product/StockDetails/Summary.phtml');
}
/**
* Return current product instance
*
* @return Mage_Catalog_Model_Product
*/
public function getProduct()
{
return Mage::registry('product');
}
}
は、以前私はちょうどcreateBlock関数を呼び出すことができました。私はこの機能を呼び出せない何かを見落としているのですか?
Summary.phtml:
<div class="stock-details-summary">
<table border="0">
<tr>
<td class="a-right"><?php echo $this->__('Waiting for delivery'); ?> : </td>
<td class="a-right"><?php echo ($this->getWaitingForDeliveryQty() ? $this->getWaitingForDeliveryQty() : 0); ?></td>
</tr>
<tr>
<td class="a-right">
<?php echo $this->__('Manual supply need'); ?> :
<?php if ($this->getManualSupplyNeedQty() > 0): ?>
<i><?php echo $this->getProduct()->getmanual_supply_need_comments(); ?></i>
<?php endif; ?>
</td>
<td class="a-right">
<?php echo $this->getManualSupplyNeedQty(); ?>
</td>
</tr>
<tr>
<td class="a-right"><?php echo $this->__('Min qty to purchase'); ?> : </td>
<td class="a-right"><font color="red"><?php echo $this->getTotalNeededQtyForValidOrdersMinusWaitingForDelivery(); ?></font></td>
</tr>
<tr>
<td class="a-right"><?php echo $this->__('Max qty to purchase'); ?> : </td>
<td class="a-right" width="60"><font color="red"><?php echo $this->getTotalNeededQtyMinusWaitingForDelivery(); ?></font></td>
</tr>
<tr>
<td class="a-right"><?php echo $this->__('Status'); ?> : </td>
<td class="a-right"><?php echo $this->getGeneralStatus(); ?></td>
</tr>
</table>
</div>
しかし、彼がいない、ブロッククラスでそれをしませんか? – Zyava
このブロックにレイアウトが設定されていないように見えます。 Mage :: app() - > getLayout()は、現在のハンドル用に読み込まれたレイアウトを返します。 – Sergey
@Sergy部分的に正しい。レイアウトは設定されていません(上記の答えを更新してください)が、 'Mage :: app() - > getLayout()'はブロックを管理する単なるオブジェクトインスタンスです。ハンドルは 'Mage_Core_Model_Layout_Update'の助けを借りてブロックを追加するために使われているかもしれません。 – benmarks