Cannot send headers; headers already sent
-
02-10-2020 - |
Question
I have used renderer in a file in custom extension for attribute label but getting above error.
my code is below:
<?php
class Baltech_Stock_Block_Adminhtml_Stock_Renderer_Size extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
$value = $row->getData($this->getColumn()->getIndex());
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'size');
$options = array();
foreach( $attribute->getSource()->getAllOptions(true, true) as $option ) {
$id = $option['value'];
if ($id==$value)
{
echo $option['label'];
}
}
}
}
Solution
You can not use echo here. Instead of echo you have to use return from this method :
<?php
class Baltech_Stock_Block_Adminhtml_Stock_Renderer_Size extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
$value = $row->getData($this->getColumn()->getIndex());
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'size');
$options = array();
foreach( $attribute->getSource()->getAllOptions(true, true) as $option ) {
$id = $option['value'];
if ($id==$value)
{
return $option['label'];
}
}
}}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange