Jump to:

23377 Posts in 18296 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Using Map on silverstripe 3 dataobject

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

Page: 1
Go to End
Author Topic: 1478 Views
  • Scott Farmer
    Avatar
    Community Member
    35 Posts

    Using Map on silverstripe 3 dataobject Link to this post

    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

  • Fraser
    Avatar
    Community Member
    46 Posts

    Re: Using Map on silverstripe 3 dataobject Link to this post

    I'm also curious about this

  • simon_w
    Avatar
    Forum Moderator
    471 Posts

    Re: Using Map on silverstripe 3 dataobject Link to this post

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

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