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.

General Questions /

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

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

Creating option list from DataObject


Go to End


3 Posts   1440 Views

Avatar
okotoker

Community Member, 50 Posts

17 September 2011 at 10:51am

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.

Community Member, 309 Posts

17 September 2011 at 2:48pm

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

Community Member, 50 Posts

21 September 2011 at 3:42pm

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