Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » files won't display on website

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 837 Views
  • janulka
    Avatar
    Community Member
    80 Posts

    files won't display on website Link to this post

    Files, or "Vedlegg" dataobjects do appear in CMS, but they won't show on website..

    Vedlegg.php:

    <?php

    class Vedlegg extends DataObject
    {
       static $db = array (
          'Navn' => 'Text',
          'Beskrivelse' => 'Text'
       );

       static $has_one = array (
          'Fil' => 'File',
          'VedleggSide' => 'VedleggSide'
       );

       public function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextField('Navn'),
             new TextareaField('Beskrivelse'),
             new FileIFrameField('Fil')
          );
       }
    }

    ?>

    VedleggSide.php:

    <?php

    class VedleggSide extends Page {
       
       public static $db = array(
       );
       
       public static $has_one = array(
       );
       
       static $icon = "images/treeicons/folder";
       
       function getCMSFields() {
        $fields = parent::getCMSFields();
       
        $manager = new FileDataObjectManager(
             $this, // Controller
             'Vedlegg', // Source name
             'Vedlegg', // Source class
             'Fil', // File name on DataObject
             array(
                'Navn' => 'Navn',
                'Beskrivelse' => 'Beskrivelse'
             ), // Headings
             'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
             // Filter clause
             // Sort clause
             // Join clause
          );
    $fields->addFieldToTab("Root.Content.Vedlegg",$manager);
             
        return $fields;
       }
       
    }

    class VedleggSide_Controller extends Page_Controller {
       
    }

    ?>

    Layout/VedleggSide.ss:

    <% if Vedlegg %>
       
    <h2>Filer til nedlasting</h2>

    <div class="vedlegg">
    <ul>
    <% control Vedlegg %>
    <li<% if FirstLast %> class="$FirstLast"<% end_if %>><% control Fil %><img src="$icon" width="16" height="16" /><% end_control %>&nbsp; &nbsp;<a href="<% control Fil %>$Link<% end_control %>">$Navn</a>
    <% if Beskrivelse %><br />$Beskrivelse<% end_if %></li>
    <% end_control %>
    </ul>
    </div>

    <% end_if %>

    plz, what I am doing wrong here? thanks!

  • UncleCheese
    Avatar
    4085 Posts

    Re: files won't display on website Link to this post

    You forgot your has_many!

    837 Views
Page: 1
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.