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   1742 Views

Avatar
Scott Farmer

Community Member, 42 Posts

29 August 2012 at 12:12pm

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

Community Member, 47 Posts

6 September 2012 at 1:31pm

I'm also curious about this

Avatar
simon_w

Forum Moderator, 474 Posts

6 September 2012 at 2:34pm

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');