Set Default Image

Hello Friends…

          In the gridview I want to show that if there is no images are uploaded it will take default image Otherwise it shows the uploaded image . how can I done this help me out?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?

Use the ternary operator. Something like this




'value' => '(file_exists(your/route/to/the/image.jpg) ? [url="http://www.yiiframework.com/doc/api/1.1/CHtml#image-detail"]The uploaded image[/url] : [url="http://www.yiiframework.com/doc/api/1.1/CHtml#image-detail"]The default mage[/url])',



Checks if the uploaded image exists and if it’s true, print it with CHtml::image, else, prints the default image.

if you have image path saved in the database it should be fairly easy




'columns'=>array(

...

    array(

        "name" => "image"

        "value" => "empty($data->image) ? 'images/default.jpg' : $data->image",

    )

...

)