Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » How to Relate Dataobject with page?

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

Page: 1
Go to End
Author Topic: 284 Views
  • anudeepgi
    Avatar
    Community Member
    11 Posts

    How to Relate Dataobject with page? Link to this post

    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 ..

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: How to Relate Dataobject with page? Link to this post

    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.

  • anudeepgi
    Avatar
    Community Member
    11 Posts

    Re: How to Relate Dataobject with page? Link to this post

    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

    284 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.