Hi,
Pretty new to Silverstripe and I'm having a few issues getting to where I want to be. The goal is to have the CMS user upload a lot of documents, while entering information for each document as required (such as a document summary and category - Should note, I'm not looking for a bulk upload feature) and for that to then be displayed in a list with all other files that match the category.
I'm trying to create the document as a Dataobject, so the user will use the GridField to manage the displaying documents. My main issue at the moment is I can't work out how to access any of the file information from within HomePage in the CMS. Such things as the filename, file type, size, etc.
All googling and documentation I've found seems to either be with the Image class (I'm not dealing with images) or from 2009 and well out of date.
Any help on what I can do to better this would be appreciated.
class HomePage extends Page
{
static $has_many = array(
'Documents' => 'Document'
);
public function getCMSFields()
{
$fields = parent::getCMSFields();
$gridFieldConfig = GridFieldConfig_RecordEditor::create();
$gridFieldConfig->getComponentByType('GridFieldDataColumns')->setDisplayFields(array(
'Title' => 'Document Name',
'Summary' => 'Summary',
));
$resources = GridField::create('Documents', 'Resource Documents', $this->Documents(), $gridFieldConfig);
$fields->addFieldToTab("Root.Resources", $resources);
$fields->removeByName('Content');
$fields->removeByName('Metadata');
return $fields;
}
}
class Document extends DataObject
{
static $db = array(
'Title' => 'Varchar',
'Summary' => 'Text',
);
static $has_one = array(
'ResourceDocument' => 'File',
'HomePage' => 'HomePage',
);
function getCMSFields()
{
$fields = parent::getCMSFields();
$upload = new UploadField('ResourceDocument');
$upload->setConfig('allowedMaxFileNumber', 1);
$upload->allowedExtensions = array('doc', 'docx');
$upload->setCanAttachExisting(false);
$fields->addFieldToTab('Root.Main', $upload);
$upload->setFolderName('resources');
return $fields;
}
}