1

I was Created one Custom Module. In that Module Image uploaded from the Backend Side, now I want to Fetch Image on Frontend Side not image name. Can Any one help me? Any kind of help will appreciated.

Here is my phtml file :

<?php    
     $collection = Mage::getModel('recipe/recipe')->getCollection();


?>

    <?php   echo "<table border=2>
            <tr>
            <th><b>Category Id</th>
            <th><b>Category Name</th>
            <th><b>Category Slug</th>
            <th><b>Category Image</th>
            <th><b>Parent Category</th>
            <th><b>Creation Time</th>
            <th><b>Update Time</th>
            <th><b>Status</th>
            </tr>";


    foreach($collection as $data)
    {
?>  

        <tr>
            <td><?php echo $data->getId(); ?>
                <td><?php echo $data->getCategoryName();?>
                <td><?php echo $data->getCategorySlug();?>

                <td><?php echo $data->getCategoryImage();?></td>
                <td><?php echo $data->getParentCategory();?>
                <td><?php echo $data->getCreatedTime();?>
                <td><?php echo $data->getUpdateTime();?>
                <td><?php echo $data->getStatus();?>

            </tr>

<?php   
    }

?> 
    </table>

And also in database my image filed name is category_image

5
  • are you saving image in DB? Dec 29, 2016 at 5:38
  • @Ashish Madankar : yes I am saving image in DB. but only image name. Dec 29, 2016 at 5:40
  • @H_Parekh can you provide code and database detail so anyone can understand better your scenario Dec 29, 2016 at 6:15
  • @ Murtuza Zabuawala : I am Edit my question , now you can see code. Dec 29, 2016 at 6:39
  • Where are you saving your images?
    – Piyush
    Dec 29, 2016 at 7:01

2 Answers 2

1

in your td please try below code

  <td> <img src="<?php echo Mage::getBaseUrl('media/category_image'). $data->getCategoryImage(); ?>">

and If your image is in root directory of media then image will appeared

3
  • :my image directory is media/category_image Dec 29, 2016 at 7:05
  • @H_Parekh check updated answer Dec 29, 2016 at 7:06
  • @H_Parekh You are always welcome :) Dec 29, 2016 at 7:22
1

You can load your module

$model = Mage::getModel('vendor/model')->load(the required id);

Then You can call the Image Field for Example your Field name is image in DB

$model->getImage() // this will give you image name 

Then In your phtml file you can create img tag to display

$imagePath = Mage::getBaseUrl('media') . 'vendorName/';
<img src="<?php $imagePath.$model->getImage() ?>" alt="<?php $model->getTitle() ?>"/>

Note: I have given an example so the following image should be in such dir

<magento root>/media/vendorName/Image.jpg

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.