Display Image With Controller

Hello everyone.

I am having problem with displaying image, can any one please suggest how to solve this? It took lot of hours already




<a href='calling controller action here for original image' rel="album1"><img src='calling controller action here for thumb'>



I am calling the above in a for loop and displaying those images in the colorbox with below code.




$colorbox

  ->addInstance('.colorbox', array('maxHeight'=>'80%', 'maxWidth'=>'90%'))

  ->addInstance('.colorbox1', array('iframe'=>true, 'width'=>'80%', 'height'=>'80%'))          ->addInstance('a[rel="album1"]');



Thumbs are displaying perfectly because they are in <img> tag. but when I click on thumb image, <a href> is getting called to display original image using controller action and the data is displaying as binary data…

I understand we need only <img> tag to display image. How can I overcome to display href link as image?

any help will be much appreciated.

Thanks in Advance

Hi you can display an image inside an view by

<?php echo CHtml::image($this->createUrl(‘download’,array(‘file’=>$model->thumbnail_url)),‘logo’,array(‘style’=>‘width:250px;’))?>

and write download function in your controller.

public function actionDownload($id = null)

{


	&#036;imgFile = Yii::app()-&gt;basePath .'/..' . IMAGE_UPLOAD_PATH  . '&#46;&#46;/images/default_user.jpg'; // here you can set default image if image not present


	


	if ( &#036;id ) &#036;model = modelname::model()-&gt;findByPk(&#036;id);





	if ( isset(&#036;model) &amp;&amp; &#33;empty(&#036;model-&gt;image))


	{


		&#036;imgFile = Yii::app()-&gt;basePath .'/..' . IMAGE_UPLOAD_PATH  . &#036;model-&gt;image;


	}





	if ( file_exists(&#036;imgFile))


	{


		&#036;request = Yii::app()-&gt;getRequest();


		&#036;request-&gt;sendFile(basename(&#036;imgFile),file_get_contents(&#036;imgFile));


	}


	throw new CHttpException(404, Yii::t('thescout', 'You are not allowed to access this page.'));





}