Fatal error: Declaration of \ModuleName\Block\Adminhtml\ModuleName\Grid\Renderer\Image::render() must be compatible with Magento\Backend\Block\Widget\Grid\Column\Renderer\RendererInterface::render(Magento\Framework\DataObject $row) in C:\wamp\www\magento2\app\code\\ModuleName\Block\Adminhtml\ModuleName\Grid\Renderer\Image.php on line 59
<?php
namespace <vendor-name>\ModuleName\Block\Adminhtml\ModuleName\Grid\Renderer;
use Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer;
use Magento\Framework\Object;
use Magento\Store\Model\StoreManagerInterface;
class Image extends AbstractRenderer
{
private $_storeManager;
/**
* @param \Magento\Backend\Block\Context $context
* @param array $data
*/
public function __construct(\Magento\Backend\Block\Context $context, StoreManagerInterface $storemanager, array $data = [])
{
$this->_storeManager = $storemanager;
parent::__construct($context, $data);
$this->_authorization = $context->getAuthorization();
echo "test";
}
/**
* Renders grid column
*
* @param Object $row
* @return string
*/
public function render(Object $row)
{
$mediaDirectory = $this->_storeManager->getStore()->getBaseUrl(
\Magento\Framework\UrlInterface::URL_TYPE_MEDIA
);
$imageUrl = $mediaDirectory.'/FolderPathName'.$this->_getValue($row);
return '<img src="'.$imageUrl.'" width="50"/>';
}
}
-
2PHP expects, that the method signature is the same for a child class.Fabian Blechschmidt– Fabian Blechschmidt2016年04月09日 08:42:33 +00:00Commented Apr 9, 2016 at 8:42
1 Answer 1
As stated by Fabian in the comment your child class method signature is different from the parent class.
The parent method from AbstractRenderer is
public function render(DataObject $row)
{
if ($this->getColumn()->getEditable()) {
$result = '<div class="admin__grid-control">';
$result .= $this->getColumn()->getEditOnly() ? ''
: '<span class="admin__grid-control-value">' . $this->_getValue($row) . '</span>';
return $result . $this->_getInputValueElement($row) . '</div>' ;
}
return $this->_getValue($row);
}
Do you notice the difference with your method?
Your method parameters is Object $row where it should be Magento\Framework\DataObject $row.
-
1Additional info.
Magento\Framework\Objectdoes not exist anymore. it was turned toMagento\Framework\DataObjectto make Magento2 compatible with php7Marius– Marius2016年04月09日 20:35:44 +00:00Commented Apr 9, 2016 at 20:35 -
I am using php 5.6 but still facing the same issueParas Arora– Paras Arora2016年10月04日 05:16:34 +00:00Commented Oct 4, 2016 at 5:16