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.

General Questions /

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

Unable to display attached files in template [SOLVED]


Reply


5 Posts   1256 Views

Avatar
neografik

Community Member, 7 Posts

25 February 2011 at 10:36am

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 {
}

Avatar
Ryan M.

Community Member, 309 Posts

25 February 2011 at 10:44am

Try $MyFile.Filename

Avatar
neografik

Community Member, 7 Posts

25 February 2011 at 10:55am

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

Avatar
neografik

Community Member, 7 Posts

25 February 2011 at 10:29pm

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

Avatar
neografik

Community Member, 7 Posts

26 February 2011 at 12:42am

Edited: 26/02/2011 12:43am

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