0

hello everyone I want to display the image through image name in a custom tab in admin grid image name is coming but now I want to display the image code to display the image name info.php

 $fieldset->addField(
        'image',
        'text',
        [
            'name'        => 'image',
            'label'    => __('image'),
           'required'     => true,

        ]
    ); 

through this code image name is coming now i want to display the image enter image description here

1 Answer 1

0

If you want to show image in grid that is possible, but if you want to show image in form, that wont be possible in magento, because image is not input field it would not appear on form.

But you can use image uploader instead of text field in you from

$this->addColumn(
    'image',
    [
        'header' => __('Image'),
        'index' => 'image',
        'type' => 'image',
        'frame_callback' => array($this, 'callback_image'),
    ]
);

To show image in grid you can do this:

$this->addColumn(
    'image',
    [
        'header' => __('Image'),
        'index' => 'image',
        'type' => 'image',
        'frame_callback' => array($this, 'callback_image'),
    ]
);

frame callback function 'frame_callback' => array($this, 'callback_image'), will call a function and it runs like renderer

Function is:

public function callback_image($value)
{
    if (empty($value)){
        return '';
    }
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $mediaUrl = $objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
    $width = 150;
    return "<img src='" . $mediaUrl . "LOCATION_OF_IMAGE" . $value . "' width='" . $width . "'/>";
}

Do these in your grid file, and image will appear on grid, instead of URL

4
  • i want it in form not in grid Commented Mar 5, 2019 at 10:39
  • I have Updated my answer, you can use image uploader in your form, this will show you image thumbnail of uploaded image and browse button at the same time. But you will need to add image uploading functionality in your Save.php controller Commented Mar 5, 2019 at 10:41
  • You can not show just image in your form, because image is not an input, and magento only allows input elements in form Commented Mar 5, 2019 at 10:42
  • i want to show image url in form Commented Mar 5, 2019 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.