Jump to:

23007 Posts in 11866 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Unable to display attached files in template [SOLVED]

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1080 Views
  • neografik
    Avatar
    Community Member
    7 Posts

    Unable to display attached files in template [SOLVED] Link to this post

    Hello!

    I have problem to display attached files. Files to attach and display a list of DOM (Uploadify). Generated link does not work. Does my template is all ok?

    OfertaHolder.ss
    -----------------------
    <% if Plik %>
    <% control Plik %>
    pobierz plik: <a href="$MyFile.URL">$MyFile.Title ($MyFile.Size) [$MyFile.Extension]</a>

    <% end_control %>
    <% end_if %>
    ------

    This is my code:

    MyFile.php:
    --------------

    <?php
    class MyFile extends File {
    static $has_one = array (
    'OfertaPage' => 'OfertaPage'
    );
    }
    ------

    OfertaPage.php:
    --------------
    <?php
    class OfertaPage extends Page {
    static $db = array(
    'Pokazemail' => 'Boolean',
    'Pokaztel' => 'Boolean',

    'Imienazwisko' => 'Text',
    'Tel' => 'Text',
    'Email' => 'Text'
    );
    static $has_one = array(
    'Zdjecie' => 'Image'
    );

    static $has_many = array (
    'Plik' => 'MyFile'
    );

    function getCMSFields() {
    $fields = parent::getCMSFields();

    $fields->addFieldToTab("Root.Content.Images", new ImageField('Zdjecie'));
    $fields->addFieldToTab("Root.Content.File", $MFile = new MultipleFileUploadField('Plik'));

    $fields->addFieldToTab('Root.Content.Main', new TextField('Imienazwisko', 'Imię i nazwisko'), 'Content');

    $fields->addFieldToTab('Root.Content.Main', new CheckboxField ('Pokaztel', 'Pokaż tel lub www'), 'Content');
    $fields->addFieldToTab('Root.Content.Main', new TextField('Tel'), 'Content');

    $fields->addFieldToTab('Root.Content.Main', new CheckboxField ('Pokazemail', 'Pokaż email'), 'Content');
    $fields->addFieldToTab('Root.Content.Main', new TextField('Email'), 'Content');

    $MFile ->allowFolderSelection();

    return $fields;
    }
    }
    class OfertaPage_Controller extends Page_Controller {
    }

  • Ryan M.
    Avatar
    Community Member
    309 Posts

    Re: Unable to display attached files in template [SOLVED] Link to this post

    Try $MyFile.Filename

  • neografik
    Avatar
    Community Member
    7 Posts

    Re: Unable to display attached files in template [SOLVED] Link to this post

    Does't work Title, link don't display - is empty...

  • neografik
    Avatar
    Community Member
    7 Posts

    Re: Unable to display attached files in template [SOLVED] Link to this post

    Maybe there is another way to load multiple files and displays them in a template?

  • neografik
    Avatar
    Community Member
    7 Posts

    Re: Unable to display attached files in template [SOLVED] Link to this post

    Big Thanks to Matt Clegg!! Now work fine.

    I had a bug in the template, correct code:

    <% if Plik %>
    <% control Plik %>
    pobierz plik: <a href="$URL">$Title ($Size) [$Extension]</a>

    <% end_control %>
    <% end_if %>

    1080 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.