Checking if view exists?

check your case… as linux is case-sensitive…

Try something like this:


$im1=Yii::app()->basePath.'/../images/'.$model->id.'_3.jpg';//protected and images are at the same level




checked…

There should be a problem with “is_file($im1)” because it works with thisv(just for test:it’s not what I want)





<?php

$im1='..'.Yii::app()->request->baseUrl.'/images/'.$model->id.'_3.jpg';

if (1==1){ ?><a href="<?php echo $im1 ?>"><img width="100px" height="100px" src="<?php echo $im1?>"/></a>


<?php }?>



I supposed you wanted to achieve something like this (pseudocode):


$url=Yii::app()->request->baseUrl;

$path=Yii::app()->basePath;

if(file_exists($path . '/images/'.$model->id.'_3.jpg')

    echo '<img src="'. $url.'/images/'.$model->id.'_3.jpg' ...;

I’m kind of out of this topic right know, but if I’m not mistaken I noticed a few days ago that path sent to PHP’s file_exists function IS NOT the same path that can be accepted by HTML’s img tag! I mean - I had an situation, where file_exits was returning true, but image was not loaded corectly within img tag.

This was probably due to using relative paths acceptable by PHP function but somehow being rejected by img tag. In that particular situation I had no need (neither time) to dig this problem little bit to try to find source of the problem and I just resigned of using file_exists. Here, I just wanted to let you know that I run into such problem once.




if (!Yii::App()->controller->getViewFile('//relative/view/path'))

      //view does not exist



This also takes themes into account

At least nowadays this quick and easy method works:




if ($this->getViewFile($item['view'])) {

    $this->renderPartial($item['view'], NULL, true);

}



PS It’s a shame that this thread never got a proper answer before and instead was hijacked since google searches on the subject still leads here.