Skip to content

Instantly share code, notes, and snippets.

@maximishchenko
Created September 17, 2015 17:17
Show Gist options
  • Save maximishchenko/f7138dfb6fe9132692f9 to your computer and use it in GitHub Desktop.
Save maximishchenko/f7138dfb6fe9132692f9 to your computer and use it in GitHub Desktop.
Yii if image exist show image else show nophoto.png
<?php
echo !empty($model-><field>) && file_exists(Yii::getPathOfAlias('webroot.images')."<PATH>".$model-><field>) ? CHtml::image(Yii::app()->baseurl."<PATH>".$model-><field>,"",array("style"=>"width:50px;height:50px;align:center;")) : CHtml::image(Yii::app()->baseurl."/<PATH>/no_img.png","",array("style"=>"width:50px;height:50px;align:center;"));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment