21492 Posts in 5783 Topics by 2621 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 644 Views |
-
Gridfield with relationEditor has_one Dataobject

29 June 2012 at 8:05pm
hello
I got few guestions about gridfield and creating new dataobject thereI 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 relationI want just create DataObject and then upload Image without set this relation
any suggestions??? -
Re: Gridfield with relationEditor has_one Dataobject

10 February 2013 at 12:45am
Noticed a typo in your code, ArticlePhotoGallert - should this be ArticlePhotoGallery?
-
Re: Gridfield with relationEditor has_one Dataobject

10 February 2013 at 12:45am
Noticed a typo in your code, ArticlePhotoGallert - should this be ArticlePhotoGallery?
-
Re: Gridfield with relationEditor has_one Dataobject

26 February 2013 at 4:30am Last edited: 26 February 2013 4:34am
This is a problem I have too. There doesn't seem to be any solution for adding/editing/deleting objects that are attached through a has_one.
Sorry I can't help, I'm looking into a way to do this.
-
Re: Gridfield with relationEditor has_one Dataobject

26 February 2013 at 8:43pm Last edited: 26 February 2013 8:44pm
thanks for help
i started using multiple upload field for this
| 644 Views | ||
|
Page:
1
|
Go to Top |

