hello
I got few guestions about gridfield and creating new dataobject there
I want create photogallery for article pages so I got this code
class ArticlePhoto extends DataObject
{
public static $singular_name = 'Obrázok k článku';
public static $db = array (
'Title' => 'text'
);
public static $has_one = array (
'Image' => 'Image',
'Page' => 'Page',
);
}
class Article extends Page
{
public static $has_many = array(
'ArticlePhotos' => 'ArticlePhoto'
);
public function getCMSFields()
{
$f = parent::getCMSFields();
$dl = DataList::create('ArticlePhoto')
->where('PageID ='.$this->ID);
$config = new GridFieldConfig_RelationEditor();
$gridField = new GridField('ArticlePhotos','ArticlePhotoGallert', $dl,$config);
$f -> addFieldToTab('Root.PhotoGallery', $gridField);
return $f;
}
}
I want use this DataObject for more page subclasses so for that is is in has_one Page class
it looks like really simple code but my probles is how to set automatically dataobject has_one page
when I create new dataobject this is not automatically set and I am redirected to page with ID = 1
when I delete filter '->where('PageID ='.$this->ID);' everything works fine but I still have to set this relation
I want just create DataObject and then upload Image without set this relation
any suggestions???