Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

TableListField to show uploaded file link?

Go to End

4 Posts   2833 Views


Community Member, 2 Posts

15 April 2009 at 5:30pm

Edited: 15/04/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(
			'ID' => 'ID',
			'Created' => 'Date/Time',
			'FirstName' => 'First Name',
			'LastName' => 'Last Name',
			'Email' => 'Email Address',
			'Attachment' => ''
		'Email' => '<a href=\"mailto: $Email\" title=\"Email $FirstName\">$Email</a>',
		'Attachment' => '<a href=\"$Attachment.URL\" title=\"$Attachment.Title\">$Attachment.Title</a>'
		'Created' => 'Date->Nice'
	if(isset($_REQUEST['printable'])) {
	} else {
	return $report;


Community Member, 2 Posts

19 April 2009 at 12:21pm

Edited: 19/04/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', 


Community Member, 80 Posts

2 June 2009 at 10:57am

change the following line:

<a href=\"$Attachment.URL\" title=\"$Attachment.Title\">$Attachment.Title</a>


<a href=\"$Attachment.Filename\" title=\"$Attachment.Title\">$Attachment.Title</a>


Community Member, 80 Posts

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!