Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » FileDataObjectManager - question?

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2 3 4
Go to End
Author Topic: 4151 Views
  • ulysses
    Avatar
    Community Member
    57 Posts

    Re: FileDataObjectManager - question? Link to this post

    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?

  • ulysses
    Avatar
    Community Member
    57 Posts

    Re: FileDataObjectManager - question? Link to this post

    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.

  • FireMe!
    Avatar
    Community Member
    74 Posts

    Re: FileDataObjectManager - question? Link to this post

    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

  • ulysses
    Avatar
    Community Member
    57 Posts

    Re: FileDataObjectManager - question? Link to this post

    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

  • FireMe!
    Avatar
    Community Member
    74 Posts

    Re: FileDataObjectManager - question? Link to this post

    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 %>

  • ulysses
    Avatar
    Community Member
    57 Posts

    Re: FileDataObjectManager - question? Link to this post

    Thanks for your help. got that going now.

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

  • FireMe!
    Avatar
    Community Member
    74 Posts

    Re: FileDataObjectManager - question? Link to this post

    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!

  • ulysses
    Avatar
    Community Member
    57 Posts

    Re: FileDataObjectManager - question? Link to this post

    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/

    4151 Views
Page: 1 2 3 4
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.