0

I have a database with images associated to each entry.

Anyhow, some entries don't have an image.

Googling I found some js and php way to apply in the view, but I'm pretty sure there is a (much nicer) MVC-way to do this, just I don't know how..

Is there a nice Cake-way to display placeholder image where none exist?

tereško
  • 58,060
  • 25
  • 98
  • 150
3und80
  • 364
  • 6
  • 20

2 Answers2

1

Supposed the data you set from the controller named 'post'. And you have 'your_default_image' in your /app/webroot/img/

<?php
if(empty($post['Post']['img'])) {
    echo $this->Html->image($post['Post']['img']);
} else {
    echo $this->Html->image('your_default_image');
}

And you can wrap those logic in your helper.

hope_is_grim
  • 1,934
  • 15
  • 24
  • Thanks, works fine. If it helps others, you might need to change "isset" to "empty", depending on the entry in your db. Try and error.. – 3und80 Oct 07 '12 at 10:42
-1

You can use placehold.it anywhere you need for placeholding images.

Just use http://placehold.it/WxH like http://placehold.it/250x250 and you're set.

Lucas Freitas
  • 194
  • 12