In my backend controller I use the following code to render a custom block.
$this->_title($this->__('Inventar'));
$this->loadLayout();
$this->_setActiveMenu('psp_inventorymanager');
$this->_addContent($this->getLayout()->createBlock('psp_inventorymanager/adminhtml_importstatus'));
$this->_initLayoutMessages('customer/session');
$this->renderLayout();
But the _addContent line does not work. It works on a local magento install but not on the main site. This is the content of the block's _toHtml():
public function _toHtml()
{
$html = parent::_toHtml();
$session = Mage::getSingleton('core/session');
echo '<style>
.list-with-heading h3{
font-weight: normal;
}
.list-success {
background: green;
}
.list-fail {
background: red;
}
.list-oldqty {
background: yellow;
}
.list-with-heading {
background: #00BFFF;
border: 1px solid #000;
padding: 10px;
}
.auto {
max-height: 150px;
overflow: auto;
border: 1px solid #000;
padding: 10px;
}
</style>';
echo '<div class="list-with-heading"><h3>Successful imports: </h3><ul class="list-success auto">';
foreach ($session->getInventoryImportSuccess() as $key => $value) {
echo '<li>'. $key .'</li>';
}
echo '</ul></div>';
echo '<div class="list-with-heading"><h3>Failed imports [SKU not found]: </h3><ul class="list-fail auto">';
foreach ($session->getInventoryImportFail() as $key => $value) {
echo '<li>'. $key .'</li>';
}
echo '</ul></div>';
echo '<div class="list-with-heading"><h3>Failed imports [QTY not changed]: </h3><ul class="list-oldqty auto">';
foreach ($session->getInventoryImportOldQty() as $key => $value) {
echo '<li>'. $key .'</li>';
}
echo '</ul></div>';
$html .= "teeeeeeeeeeeeest";
return $html;
}
Edit: I have looked at the system.log and createBlock fails and returns false instead of the block.
1 Answer 1
I feel silly now. I traced createBlock and saw that I had a typo in my block's naming. I had to change
->createBlock('psp_inventorymanager/adminhtml_importstatus')
to this
->createBlock('psp_inventorymanager/adminhtml_importStatus')
answered May 3, 2016 at 12:10
igor treptau
51 silver badge4 bronze badges
default