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.

Data Model Questions /

GridFieldConfig_RelationEditor doesn`t work with upload photo


Reply


266 Views

Avatar
skv_gwww

Community Member, 1 Post

18 November 2013 at 11:43pm

Hi, i`m a silverstripe beginner.
I need to do some kind of gallery catalog, so i decided to make it with GridFieldConfig_RelationEditor

1 girl can have many photos and can belong to one gallery
1 gallery can have many girls

Here is my problem:

##mysyte/code/Girl.php

<?php
class Girl extends DataObject {
private static $db = array(
'Name' => 'Varchar',
'Description' => 'Varchar',
);
private static $has_one = array(
'Gallery' => 'Gallery'
);
/*
private static $has_many = array(
'Photo' => 'Image'
);
*/
public function getCMSFields() {
$fields = parent::getCMSFields();
//$fields->addFieldToTab('Root.Photo', new UploadField('Photo'));
return $fields;
}
}

##mysyte/code/Gallery.php
<?php
class Gallery extends Page {
private static $has_many = array(
'Girls' => 'Girl'
);

public function getCMSFields() {
$fields = parent::getCMSFields();
$config = GridFieldConfig_RelationEditor::create();
$girlsField = new GridField(
'Name', // Field name
'Girl', // Field title
$this->Girls(),
$config
);

// Create a tab named "Girls" and add our field to it
$fields->addFieldToTab('Root.Girls', $girlsField);
return $fields;
}

}
class Gallery_Controller extends Page_Controller {
}

This code works fine, but when i`m uncomenting parts with uploading images in Girl.php file,
my code doesn`t work.
Does any body knows where is the problem? Thank you.