hey,
i have the following controller:
class ImagePage_Controller extends Page_Controller {
function download() {
$id = Director::urlParam('ID');
if ($id) {
//get a File object or subclass of (e.g. Image)
$image = DataObject::get_by_id("Image",$id);
$path = $image->getFullPath();
$name = basename($path);
$response = new HttpResponse();
$response->setBody(file_get_contents($path));
$response->addHeader("Content-disposition","attachment; filename=" . $name);
return $response;
} else
return false;
}
}
and the following template:
<% control Images %>
<div class="images">
<% control Attachment %>$CroppedImage(100,100)<% end_control %>
<p><a href="$Attachment.GetURL" title="download">download</a></p>
<div class="clearleft"></div>
</div>
<% end_control %>
Images is an DataObject, which contains an Image in field 'attachment'.
What i am trying to do is:
Instead of linking to the direct file, i want to call the download-Function of the controller with the id if the image. Something like:
<p><a href="$Link(download)/$Attachment.ID" title="download">download</a></p>
But i cannot access the '$Link' inside a control. Is there any way to achieve this?
any ideas or solutions?
thanks
escaped