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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

FileDataObjectManager - question?


Go to End


30 Posts   6659 Views

Avatar
ulysses

Community Member, 57 Posts

20 May 2009 at 10:25pm

Hi UncleCheese. I have got the Add Resource button display in the CMs and can upload files to the server but how do I display the file documents uploaded on the on the web site?

Avatar
ulysses

Community Member, 57 Posts

20 May 2009 at 10:28pm

Edited: 21/05/2009 12:49am

Hello FireMe!

Thanks to your request for help, I have got the Add Resource button working on the CMS but can you please tell me what you need to add to the page template to display the upload resource files.

I have also added $Resources on the page.ss below $Content

The resource files uploaded names get displayed on the front end but links directly to the root of the site.

How can you make it display the correct link to file on the server, the file date and the size of the file?

Thanks for your help.

Avatar
FireMe!

Community Member, 74 Posts

21 May 2009 at 1:24am

hi ulysses

this is my resource page template

<h1>Forms</h1>
<% control FilterForms %>
<div id="downloads">
  <h3>$Name</h3>
  <p>$Description</p>
  <p><b>Category:</b> $Category <b>File type:</b> $Attachment.FileType <b>File Size:</b> $Attachment.Size <b>Download:</b> <a href="$Attachment.URL">$Name</a>
</div>
<% end_control %>

<h1>Videos</h1>

<% control FilterVideos %>
<div id="downloads">
  <h3>$Name</h3>
  <p>$Description</p>
  <p><b>Category:</b> $Category <b>File type:</b> $Attachment.FileType <b>File Size:</b> $Attachment.Size <b>Download:</b> <a href="$Attachment.URL">$Name</a>
</div>
<% end_control %>

so the main ones for calling are

$Attachment
so you would just add .FileType or .size .URL for link
 $Attachment.FileType  $Attachment.Size  <a href="$Attachment.URL">$Name</a> 

plus there is

$Category $Description $Name
for calling the category description and name of the file

hope this helps

FireMe

Avatar
ulysses

Community Member, 57 Posts

21 May 2009 at 1:29am

Edited: 21/05/2009 1:35am

Hi FireMe,

Thanks for that info. Can you please advise where I insert this code. Fairly new to this.

I have the files Resource.php & ResourcePage.php in the /mysite/code/ folder.

I can email you my files. My email is mauricio@ulysses.co.nz

Avatar
FireMe!

Community Member, 74 Posts

21 May 2009 at 1:48am

you need to add something like this too your ResourcePage.php controller

class ResourcePage_Controller extends Page_Controller
{
function MyFileObjects()
	{
		$filter = Director::urlParam('Action');
		return $filter ? $this->Resources("Category = '$filter'") : $this->Resources();
	}
}

then you need to create a ResourcePage.ss and put in your themes folder under templates > layout

some thing like this


<% control MyFileObjects %>
<div id="downloads">
  <h3>$Name</h3>
  <p>$Description</p>
  <p><b>Category:</b> $Category <b>File type:</b> $Attachment.FileType <b>File Size:</b> $Attachment.Size <b>Download:</b> <a href="$Attachment.URL">$Name</a>
</div>
<% end_control %>

Avatar
ulysses

Community Member, 57 Posts

21 May 2009 at 1:58am

Thanks for your help. got that going now.

Any ideas how to add the file upload date as well?

Avatar
FireMe!

Community Member, 74 Posts

21 May 2009 at 2:10am

i think you would just have to a date field to your array on your Resource.php


<?php 
class Resource extends DataObject
{
	static $db = array (
		'Name' => 'Text',
                'Date' => 'Date',
		'Description' => 'Text',
		'Category' => "Enum('Forms, Videos')"
	);
	
	static $has_one = array (
		'Attachment' => 'File',
		'ResourcePage' => 'ResourcePage'
	);
	
	public function getCMSFields_forPopup()
	{
		return new FieldSet(
			new TextField('Name'),
                        new CalendarDateField('Date'),
                        new TextareaField('Description'),
			new DropdownField('Category','Category', singleton('Resource')->dbObject('Category')->enumValues()),
			new FileIFrameField('Attachment')
		);
	}
}
?>

but im not to sure about this, best to ask uncle cheese!

FireMe!

Avatar
ulysses

Community Member, 57 Posts

21 May 2009 at 2:22am

Hi FireMe,

You were absolutely spot on. Awesome. Thanks heaps. That's what I needed.

Check out the page under development: http://biztravel.ulysses.co.nz/test/