title: Display images from protected folder
body: <p>I have a protected folder within Yii and I'm looking to display some of those images within the site. I've tried the following code and it works within the site/index controller in that it returns just the image I wanted.</p>
  
  <p>However when I tried to separate the code it didn't work. Any help is appreciated.</p>
  
  <p><strong>Model</strong></p>
  
  <pre><code>    public function getImage() // will take file identifier as @param       
  {
  
      $imageID = '2562584569'; // will eventually be dynamically assigned
  
      $image = Images::model()-&gt;find('tmp_name=:id', array('id' =&gt; $imageID)); 
  
      $dest = Yii::getPathOfAlias('application.uploads');
  
      $file = $dest .'/' . $image-&gt;tmp_name . '.' . $image-&gt;extension;
  
      if(file_exists($file)){
      ob_clean();
      header('Content-Type:' . $image-&gt;logo_type);
      readfile($file);
      exit;
      }
  
  }
  </code></pre>
  
  <p><strong>And in the view</strong></p>
  
  <pre><code>CHtml::link('&lt;img src="' . Yii::app()-&gt;request-&gt;baseUrl .'/images/image" /&gt;', array('product/index', 'id'=&gt;$data['product_id'], 'slug'=&gt; $data['product_slug']));
  </code></pre>
  
  <p>Thanks</p>
  
  <p>Jonnny</p>