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

Can I upload a file in site content editor without having to use Files and Images tab?


Go to End
Reply


12 Posts   1657 Views

Avatar
RichHead

Community Member, 13 Posts

21 March 2010 at 11:51pm

Edited: 21/03/2010 11:52pm

I'm really struggling with the security model for a multi-user CMS site, I do not want to grant editors access to Files and Images as that seems to allow them to add/delete ANY file.

So, assuming the above is correct and I am not missing something obvious, is there a way to allow files to be uploaded that can then be linked to as a download (PDF files) from within the page content editor?

Rich

Avatar
JoshuaLewis

Community Member, 76 Posts

22 March 2010 at 7:30am

Modify mysite/code/Page.php with the following

class Page extends SiteTree {
...
$has_one = array ('pdf' => 'File');
...
public function getCMSFields(){
$fields = parent::getCMSFields();
$fields->addFieldToTab(new FileIFrameField('pdf', 'Field Title');
return $fields;
}

Or better yet create a subclass of Page. The tutorials at [url]http://doc.silverstripe.org/doku.php[/url] go into detail.

Avatar
RichHead

Community Member, 13 Posts

23 March 2010 at 10:30am

I tried this (but obviously did something wrong); as I lose the site and admin functions - just end up with a blank web site.

Here's what I have:

<?php
class Page extends SiteTree {
   
   public static $db = array(
   );
   
   public static $has_one = array(
   );

public static $has_one = array ('pdf' => 'File');

public function getCMSFields(){
$fields = parent::getCMSFields();
$fields->addFieldToTab(new FileIFrameField('pdf', 'Field Title');
return $fields;
}

class Page_Controller extends ContentController {
   
   public function init() {
      parent::init();

      // Note: you should use SS template require tags inside your templates
      // instead of putting Requirements calls here. However these are
      // included so that our older themes still work
      Requirements::themedCSS("layout");
      Requirements::themedCSS("typography");
      Requirements::themedCSS("form");
   }
   
   /**
    * Site search form
    */
   function SearchForm() {
      $searchText = isset($_REQUEST['Search']) ? $_REQUEST['Search'] : 'Search';
      $fields = new FieldSet(
       new TextField("Search", "", $searchText)
       );
      $actions = new FieldSet(
       new FormAction('results', 'Search')
       );

       return new SearchForm($this, "SearchForm", $fields, $actions);
   }
   
   /**
    * Process and render search results
    */
   function results($data, $form){
       $data = array(
       'Results' => $form->getResults(),
       'Query' => $form->getSearchQuery(),
       'Title' => 'Search Results'
       );

       return $this->customise($data)->renderWith(array('Page_results', 'Page'));
   }
   
}

?>

Avatar
Hamish

Community Member, 712 Posts

23 March 2010 at 11:34am

This line is incorrect:

   $fields->addFieldToTab(new FileIFrameField('pdf', 'Field Title');

Avatar
RichHead

Community Member, 13 Posts

23 March 2010 at 11:39am

Appreciate the reply Hamish, unfortunately I have very little (none!) PHP experience, I am simply trying to get out village community web site online...

I do not know what I need to do to correct this {embarrassed}

Avatar
JoshuaLewis

Community Member, 76 Posts

23 March 2010 at 12:19pm

Sorry about that, I didn't double check what I posted.

The location of the new field needs to be set and there should be two closing parentheses, one for FileIFameField() and another for addFieldToTab().

This should now be correct.

$fields->addFieldToTab('Root.Content.Main', new FileIFrameField('pdf', 'Field Title'));

Avatar
RichHead

Community Member, 13 Posts

23 March 2010 at 7:16pm

Thank you.. I'll give that a go later

Avatar
RichHead

Community Member, 13 Posts

24 March 2010 at 10:21am

:-(

Exactly the same result (blank page, nothing in public or admin view at all):

<?php
class Page extends SiteTree {

public static $db = array(
);

public static $has_one = array(
);

public static $has_one = array ('pdf' => 'File');

public function getCMSFields(){
$fields = parent::getCMSFields();
$fields->addFieldToTab(new FileIFrameField('pdf', 'Field Title'));
return $fields;
}

class Page_Controller extends ContentController {

public function init() {
parent::init();

// Note: you should use SS template require tags inside your templates
// instead of putting Requirements calls here. However these are
// included so that our older themes still work
Requirements::themedCSS("layout");
Requirements::themedCSS("typography");
Requirements::themedCSS("form");
}

/**
* Site search form
*/
function SearchForm() {
$searchText = isset($_REQUEST['Search']) ? $_REQUEST['Search'] : 'Search';
$fields = new FieldSet(
new TextField("Search", "", $searchText)
);
$actions = new FieldSet(
new FormAction('results', 'Search')
);

return new SearchForm($this, "SearchForm", $fields, $actions);
}

/**
* Process and render search results
*/
function results($data, $form){
$data = array(
'Results' => $form->getResults(),
'Query' => $form->getSearchQuery(),
'Title' => 'Search Results'
);

return $this->customise($data)->renderWith(array('Page_results', 'Page'));
}

}

?>

Go to Top