1

hello everyone i want to display the uploaded image my code is below info.php

$fieldset->addField(
        'image',
        'text',
        [
            'name'        => 'image',
            'label'    => __('image'),
            'renderer'  => 'Magneto\BookFreeLayout\Block\Adminhtml\Extension\Grid\Renderer\LogoImage',
            'required'     => true,

        ]
    ); 

logoimage.php

<?php

     namespace 
    Magneto\BookFreeLayout\Block\Adminhtml\Extension\Grid\Renderer;

  class LogoImage extends  
  \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer {

protected $_storeManager;

protected $_fileSystem;

protected $_modelData;

public function __construct(
    \Magento\Backend\Block\Context $context,
    \Magento\Store\Model\StoreManagerInterface $storeManager,
    \Magento\Framework\Filesystem $fileSystem,
    \Magneto\BookFreeLayout\Model\AlllayoutFactory $modelData,
    array $data = []) {
    parent::__construct($context, $data);
    $this->_storeManager = $storeManager;
    $this->_fileSystem = $fileSystem;
    $this->_modelData = $modelData;
    $this->_authorization = $context->getAuthorization();
}
public function render(\Magento\Framework\DataObject $row) {
    $id = $this->_getValue($row);
    $filepath = $this->_fileSystem->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA)->getAbsolutePath('images');
    $data = $this->_modelData->load($id);
    foreach($data as $file)
    {   
        echo "<img src='".$filepath."pub/media/images".$file['image']."' height='30' width='30' />";
    }
}

 }

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.