Hi everyone,
I have tried to search for an answer of my question in the forum or document, but could not find one.
I have a custom form (a contact form for my company website) which includes a File field. I want to show the list of all submissions in the admin page using TableListField. My code is listed below. I got the following error message "__call() Method 'forTemplate' not found in class 'File'". If I remove Attachment from below, it just works perfectly fine.
I understand that a File field doesn't have forTemplate method. The problem is how can I get the file download link correctly?
Thanks in advance if anyone can give me a hand. Appreciate that.
function getReportField() {
$resultSet = new DataObjectSet();
$filter = '';
$sort = "ContactPageSubmission.ID ASC";
$join = '';
$instance = singleton('ContactPageSubmission');
$query = $instance->buildSQL($filter, $sort, null, $join);
$report = new TableListField(
'ContactPageSubmissionReport',
'ContactPageSubmission',
array(
'ID' => 'ID',
'Created' => 'Date/Time',
'FirstName' => 'First Name',
'LastName' => 'Last Name',
'Email' => 'Email Address',
'Attachment' => ''
)
);
$report->setCustomQuery($query);
$report->setFieldFormatting(array(
'Email' => '<a href=\"mailto: $Email\" title=\"Email $FirstName\">$Email</a>',
'Attachment' => '<a href=\"$Attachment.URL\" title=\"$Attachment.Title\">$Attachment.Title</a>'
));
$report->setFieldCasting(array(
'Created' => 'Date->Nice'
));
$report->setShowPagination(true);
if(isset($_REQUEST['printable'])) {
$report->setPageSize(false);
} else {
$report->setPageSize(50);
}
$report->setPermissions(array(
'export',
'delete',
'print'
));
return $report;
}