Hi Guys,
I am creating a page type that lists out all the files in a given folder in the Assets folder. This is so that my client can simply upload files into here and they will appear on the page automatically. Should be pretty simple and it has been until I have wanted to display the file size next to the download button.
As I loop through the DocumentList control I thought I would be able to use the MyFileSize() function to simply get the file size and then display it. But unfortunately it isn't working. I have seen references to .Filesize appendix to objects but I can't get that working and perhaps I am simply just out of context so that functionality won't work.
If anyone could help it would be appreciated. I have a feeling I will go "doh" once someone points out my error/stupidity :)
Thanks,
Colin
class DocumentListPage extends Page {
public static $db = array(
'MediaFolder' => 'Text'
);
public static $has_one = array(
);
static $icon = "themes/invitro/images/treeicons/application_view_list";
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new DropdownField(
'MediaFolder',
'Display all Documents in this Folder',
array("346" => "MSDS Library",
"347" => "Media Formulations"),
'',
null,
'Display all Documents in this Folder'
), 'Content');
return $fields;
}
}
class DocumentListPage_Controller extends Page_Controller {
function DocumentList() {
return DataObject::get("File", "\"ParentID\" = '{$this->MediaFolder}'", '"Title", "Filename", "ID"');
}
function MyFileSize() {
// return $this->getSize();
return "BLAH";
}
}
TEMPLATE SECTION
<table id="">
<caption><h2>$Title <span style="float:right;padding-right: 10px;">$DocumentList.Count Document(s)</span></h2></caption>
<% control DocumentList %>
<tr>
<td class="filename">
<p>$Title</p>
<a href="$Filename">$Filename</a>
</td>
<td class="filesize"><span><a href="$Filename" style="background:none;padding:none;">$MyFileSize </a></span><br/><span class="download"><a href="$Filename" style="background:none;padding:none;">DOWNLOAD</a></span></td>
</tr>
<% end_control %>
</table>