Hi,
I am trying to build a image gallery. So far i have 2 files. ImageGalleryPage.php with a $has_many relationship with ImageGalleryEntry.php. As far as i can see, i have set the relationships up correctly, but for some reason when i try to upload a image using gridfield it does not attach the image correctly. Also when i try to use existing files in the cms i get an error message that says 'Forbidden'.
Everything else works 100%, i just can get the image to attach to the record. Here is the code:
-----------------------------------------------------------
ImageGalleryPage.php
------------------------------------------------------------
<?php
class ImageGalleryPage extends Page {
public static $db = array(
);
public static $has_many= array(
'ImageGalleryEntries'=>'ImageGalleryEntry'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$gridFieldConfig = GridFieldConfig::create()->addComponents(
new GridFieldToolbarHeader(),
new GridFieldAddNewButton('toolbar-header-right'),
new GridFieldSortableHeader(),
new GridFieldFilterHeader(),
new GridFieldDataColumns(),
new GridFieldPaginator(20),
new GridFieldEditButton(),
new GridFieldDeleteAction(),
new GridFieldDetailForm()
);
$gridfield = new GridField("ImageGalleryEntries", "Gallery Images:", $this->ImageGalleryEntries(), $gridFieldConfig);
$fields->addFieldToTab('Root.ImageGallery', $gridfield); // add grid field to tave
return $fields;
}
}
-----------------------------------------------------------
ImageGalleryEntry.php
-----------------------------------------------------------
<?php
class ImageGalleryEntry extends DataObject {
public static $db = array(
'Title'=>'Varchar(255)',
'Description'=>'Text',
'Sort' => 'Int',
'Link' => 'Text',
);
public static $has_one = array(
'ImageGalleryPage'=>'ImageGalleryPage',
'GalleryImage'=>'Image'
);
function getCMSFields() {
$fields = new FieldList (
new TextField('Title', 'Image Title'),
new TextField('Description', 'Description'),
new TextField('Sort', 'Sort Order'),
new TextField('Link', 'Image Link'),
new UploadField('GalleryImage', 'Gallery Image', $this->GalleryImage())
);
return $fields;
}
}