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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Creating option list from DataObject


Reply

3 Posts   823 Views

Avatar
okotoker

17 September 2011 at 10:51am Community Member, 41 Posts

I am creating a form and I want to populate the DropdownField with items stored in a Product DataObject. I pretty much have it working but need to access the "Option" field which is the second field and not the "Name" field which is the first field.

I am using this

      
$Options = array('' => 'Please select') + DataObject::get('Product', "$this->ID",'Option')->toDropdownMap();
      
$f = new FieldSet(
   new DropdownField('Color','Select Colour',$Options)
);

Avatar
Ryan M.

17 September 2011 at 2:48pm Community Member, 309 Posts

You might want to use this instead then.

Dataobject::get("MyObject")->map("ID", "Title", "Please Select")

See more: http://www.ssbits.com/tutorials/2010/dynamically-generating-a-dropdown-list/

Avatar
okotoker

21 September 2011 at 3:42pm Community Member, 41 Posts

That did the trick, that link had exactly the information I needed. Thanks for the help.