0

I'm trying to develop a module to show a list of categories' name and image, my controller send an array contains names and images url to my block, i want to show a default image if no image assign to any category:

-so my questions where is the better place to check if the image url is null and assign the default image url (in controller or in block).

-my second part of the question where to save this image in media or in skin folder as im planning to use it in defferent themes and i dont want to change the code every time i move it

1

Load the category and check for a valid image url

    $_category = Mage::getModel('catalog/category')->load($_categoryId);
    $_catImgUrl = $_category->getImageUrl()
    if (!$_catImgUrl) {
      $_catImgUrl=Mage::getBaseUrl('media').'yourmodule/default-image.png'
    }

I would create a media folder for your module and store the images in media/yourmodule.

  • i used something similar but i have question if i want to use skin folder how to use the current url for the theme skin folder from controller – w.k Sep 23 '15 at 16:55
  • For the skin url try Mage::getDesign()->getSkinUrl('your folder/yourfile.file') – paj Oct 1 '15 at 9:26

Your Answer

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

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