MAGENTO 2 :- Fetch image from directory and display it on table
-
15-04-2021 - |
题
right now only image Name is displaying from database table not images
<?php
foreach ($_gridrecords as $_gridrecord): ?>
<?php $employeeId=$_gridrecord->getEmployeeId() ?>
<?php $profile=$_gridrecord->getProfile()?>
<?php $name=$_gridrecord->getName() ?>
<?php $email=$_gridrecord->getEmail()?>
<?php $address=$_gridrecord->getAddress() ?>
<tr>
<td><?php echo $employeeId ?></td>
<td><?php echo $profile ?></td>
<td ><?php echo $name ?></td>
<td><?php echo $email ?></td>
<td><?php echo $address ?></td>
解决方案
First add below method in your block file
public function getImagePath()
{
$imagePath = $this->_storeManager->getStore()
->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
return $imagePath .'mycustomfolder';
}
Then your template file add this to display image
<img src="<?php echo $block->getImagePath().$your_img_var; ?>">