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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

How to Relate Dataobject with page?


Go to End


3 Posts   1353 Views

Avatar
anudeepgi

Community Member, 11 Posts

29 January 2014 at 5:44pm

Hi,
I am new to silverstripe ,I need to create Dataobject(Ex:-CarAcs extends ModelAdmin) that is related to pages what ever you created in Dataobject it will showen as dropdown menu in page so we can realate data and show it in page , Please given me a simple example of doing it with all code thanks in advance ..

Avatar
Willr

Forum Moderator, 5523 Posts

29 January 2014 at 8:02pm

Have a read of tutorial 5 (http://doc.silverstripe.org/framework/en/tutorials/5-dataobject-relationship-management). This will explain relationships and the concept of relating objects in SilverStripe.

On your Page class you might have something like

private static $has_one = array(
"Car" => "CarAcs"
);

Then in your getCMSFields for Page add the DropdownField.

public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', new DropdownField('CarID', 'Car', CarAcs::get()->map('ID', 'Title')));

return $fields;
}

Where 'CarAcs' is the name of your class. This relationship will add $page->Car() to get the car.

Avatar
anudeepgi

Community Member, 11 Posts

29 January 2014 at 8:12pm

Again Thanx bro, your always there for help.

Can you help one more time..

I need to get all infomation from Related to Cars object and pass it to view .... Please