Page 1 of 1

Change Header/Redirect Link for Certain Entity

Posted: 24 Mar 2024, 19:03
by jp05
Hi all,

I have an entity in my app that stores documents, mainly PDF files (one per entry). I then link those document(s) in other entities/subentities. To reduce the number of clicks/pages a user has to make/see before downloading the document, I added a PHP field that generates a direct download link (using "&action=download_attachment&preview=1&file="). However, that field is "executed dynamically" and not stored in the database. Further, if I link the document entity to another, especially using a "List of records by MySQL query" field, the link to the document entity redirects to the info page and not the download link.

My question is: Is there a way to change a particular entity's header/redirect link using custom PHP (or editing the code) so that when a user clicks the link, the attached document in that entry downloads? That way, if a document entity is linked using the MySQL query, clicking the item in the query would download the document rather than redirect a user to the document's item info page.

Your help is much appreciated. This app has been an amazing discovery and help for my group's work.

For example or some more context—
Document Entity
Name: Example File
Attachment: Example.pdf
Created by: User
etc.

Meeting Entity
Meeting Name: ...
Meeting Date/Time: ...
File: *select Example PDF*

In the meetings listing, it would look like—
Meeting_Name | Meeting_Date_Time | Example.pdf (link to download rather than link to entity info page)

Re: Change Header/Redirect Link for Certain Entity

Posted: 27 Apr 2024, 18:31
by eddydeniro
I don't quite understand your application scheme but if you want to display download link of your file with PHP code, you can write like this example:

Code: Select all

$filename = [XXX];
//XXX is your field ID that contains the file
$id = [id];
if(strlen($filename))
{
  $output_value = link_to('<i class="fa fa-download"></i>', url_for('items/info', 'path=YYY-'.$id.'&action=download_attachment&file=' . urlencode(base64_encode($filename)))) . ' ' . $filename;
  //YYY is your entity ID
}