Jump to:

3448 Posts in 1062 Topics by 738 members

Data Model Questions

SilverStripe Forums » Data Model Questions » merge DataObject::get

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

Page: 1
Go to End
Author Topic: 2647 Views
  • snaip
    Avatar
    Community Member
    180 Posts

    merge DataObject::get Link to this post

    i want to merge two DataObject::get and result puts into DropDownField

    first i tryed

    $en = DataObject::get("ENTourPage")->toDropdownMap('Title', 'Title');
    $home = DataObject::get("PLHomePage")->toDropdownMap('Title', 'Title');
    $en -> merge($home);

    [...]

    $fields->addFieldToTab("Root.Content.Tlumaczenie", new DropdownField('EN','Angielskie:',$wynik));

    but i get
    Fatal error: Call to a member function exists() on a non-object in ... on line ...

    second i tryed like in here http://www.silverstripe.org/data-model-questions/show/257050#post257050

    $result = new DataObjectSet();
    $result -> merge (DataObject::get("ENTourPage")->toDropdownMap('Title', 'Title'));
    $result -> merge (DataObject::get("PLHomePage")->toDropdownMap('Title', 'Title'));

    [...]
    $fields->addFieldToTab("Root.Content.Tlumaczenie", new DropdownField('EN','Angielskie:',$result));


    but now i get only empty field in DropDownField

  • Bambii7
    Avatar
    Community Member
    254 Posts

    Re: merge DataObject::get Link to this post

    I had the same problem with a system I'm trying to put together.
    But I just realized you're merging two different dataobjets, that could be a bit of an issue.
    My solution was
    $studentData = DataObject::get('Student');
    $StudentMap = $studentData->toDropDownMap('ID', 'ChildFirstName');
    foreach($studentData as $Student) {
       $StudentMap[$Student->ID] = $StudentMap[$Student->ID].' '.$Student->ChildLastName;
    }
    $students = new MultiSelectField(
       "Students", // Relationship
       "Students", // Field name
       $StudentMap // Source records (array)
    );

    But you could try something like

    $enMap = DataObject::get('ENTourPage')->toDropDownMap('ID', 'Title');//NOTE you'll want to make use of the ID not Title Title
    $home = DataObject::get("PLHomePage");
    foreach($home as $PLHomePage) {
    $enMap[$PLHomePage->ID] = $PLHomePage->Title;
    }
    $fields->addFieldToTab("Root.Content.Tlumaczenie", new DropdownField('EN','Angielskie:',$enMap));

    There might be an easier way but I'm not sure.

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