Setting The Filename Of A File As A Link For Option View/download

Can somebody teach me how to set the file name as a link to view/download that file? I have read many posts about this but it doesn’t work for me.

This is my view preview.


Screenshot from 2014-05-09 10:13:07.png

What i want is that Purchase Document to be a link.

This is my view code:

	<b><?php echo CHtml::encode($data->getAttributeLabel('purchase_document')); ?>:</b>

	<?php echo CHtml::link(CHtml::encode($model->purchase_document), Yii::app()->baseUrl . '/files/pr/' . $model->purchase_document); ?>

	<br />

I would really appreciate your help. Thank you.

You can set filename for download by adding this header line:

header('Content-Disposition: attachment; filename="downloaded.pdf"'); 

Example copied from

Try this code.

CHtml::link("Download FILE", "http://" . $_SERVER["SERVER_NAME"] . Yii::app()->request->baseUrl . "/files/pr/" . $model->purchase_document)',