21491 Posts in 5783 Topics by 2621 members
General Questions
SilverStripe Forums » General Questions » Can I upload a file in site content editor without having to use Files and Images tab?
General questions about getting started with SilverStripe that don't fit in any of the categories above.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | Next > | |
| Author | Topic: | 1195 Views |
-
Can I upload a file in site content editor without having to use Files and Images tab?

21 March 2010 at 11:51pm Last edited: 21 March 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
-
Re: Can I upload a file in site content editor without having to use Files and Images tab?

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 http://doc.silverstripe.org/doku.php go into detail.
-
Re: Can I upload a file in site content editor without having to use Files and Images tab?

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'));
}
}?>
-
Re: Can I upload a file in site content editor without having to use Files and Images tab?

23 March 2010 at 11:34am
This line is incorrect:
$fields->addFieldToTab(new FileIFrameField('pdf', 'Field Title');
-
Re: Can I upload a file in site content editor without having to use Files and Images tab?

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}
-
Re: Can I upload a file in site content editor without having to use Files and Images tab?

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'));
-
Re: Can I upload a file in site content editor without having to use Files and Images tab?

23 March 2010 at 7:16pm
Thank you.. I'll give that a go later
-
Re: Can I upload a file in site content editor without having to use Files and Images tab?

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'));
}}
?>
| 1195 Views | ||
| Go to Top | Next > |


