当前位置: 动力学知识库 > 问答 > 编程问答 >

cakephp placeholder if image not exist

问题描述:

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?

网友答案:

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.

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: