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

Using Map on silverstripe 3 dataobject


Reply

3 Posts   1590 Views

Avatar
Scott Farmer

29 August 2012 at 12:12pm Community Member, 35 Posts

Hi,

I'm using the following code to generate a dropdown list array.

function ... {
if($Pages = DataObject::get('RealestateSuburb'))
{
return $Pages->map('ID', 'Title', 'Any');
}
else
{
return array('No Objects found');
}
}

The problem is in ss3 it doesn't insert the default first item, which is "Any" in this case. Worked fine in 2.4x.

Prob a simple thing.

Thanks

Regards
Scott

Avatar
Fraser

6 September 2012 at 1:31pm Community Member, 46 Posts

I'm also curious about this

Avatar
simon_w

6 September 2012 at 2:34pm Forum Moderator, 474 Posts

You now use the emptyString value on the DropdownField for this, rather than having map() provide it. So, something like $field = new DropdownField('SuburbID', 'Suburb', $this->SuburbMap());
$field->setEmptyString('Any');