3063 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1977 Views |
-
TableListField to show uploaded file link?

15 April 2009 at 5:30pm Last edited: 15 April 2009 5:32pm
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;
} -
Re: TableListField to show uploaded file link?

19 April 2009 at 12:21pm Last edited: 19 April 2009 12:26pm
I should have provided my data model class as below:
class ContactPageSubmission extends DataObject {
static $db = array(
'FirstName' => 'Text',
'LastName' => 'Text',
'Email' => 'Text',
'Comments' => 'Text'
);static $has_one = array(
'Attachment' => 'File',
);
} -
Re: TableListField to show uploaded file link?

2 June 2009 at 10:57am
change the following line:
<a href=\"$Attachment.URL\" title=\"$Attachment.Title\">$Attachment.Title</a>
To
<a href=\"$Attachment.Filename\" title=\"$Attachment.Title\">$Attachment.Title</a>
-
Re: TableListField to show uploaded file link?

2 June 2009 at 12:35pm
By the way, I forgot to ask, where do you put the 'function getReportField()', is it in ContactUsPage.php ( class ContactUsPage extends Page )? assuming ContactUsPage.php is the page which contains the form. Thanks!
| 1977 Views | ||
|
Page:
1
|
Go to Top |

