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

select in admin area


Reply

6 Posts   1159 Views

Avatar
bebabeba

22 June 2010 at 1:35am (Last edited: 22 June 2010 1:38am), Community Member, 192 Posts

Hi!
I have a problem whit admin area..
in the right side of a standard page I see this feald:

1.Page name
2.Navigation label
3.Content

All of this are text field.
I must add a select field. What can I write in my getCMSFields functions?
I use Silverstripe v.2.3.7
Can you help me please?

Thanks

Avatar
ayyurek

22 June 2010 at 2:04am (Last edited: 22 June 2010 2:07am), Community Member, 41 Posts

Hi,

In the Page.php under mysite/code/ folder. First you should add a field where the dropdown's value will be stored.

public static $db = array (
      'Country' => 'Varchar'
   );

And then the code for creating the dropdown field.

function getCMSFields() {
$fields = parent::getCMSFields();
$array = array(
'DE' => 'Germany',
'FR' => 'France',
'ES'=> 'Spain'
);
$fields->addFieldToTab("Root.Content.Main", new DropdownField(
'Country',
'Country',
$array
);

    return $fields;
}

Don't forget to rebuild the database after these changes with http://yoursitename/dev/build/

Avatar
bebabeba

22 June 2010 at 2:19am Community Member, 192 Posts

Hi!

thanks for reply me!!
Your solution is not correct..

I try in this way..but there is an error. I see select field but is empty..

help...

static $db = array(
      'RubricType' => 'Varchar',
   );

function getCMSFields() {
      $fields = parent::getCMSFields();
      
      $array = array(
      'DE' => 'Germany',
      'FR' => 'France',
      'ES'=> 'Spain'
      );
      
      
      $fields->addFieldToTab("Root.Content.Main", new DropdownField('RubricType'),'Content',$array);
      
      return $fields;
   }

Avatar
bebabeba

22 June 2010 at 2:25am Community Member, 192 Posts

I found solution...

$fields->addFieldToTab("Root.Content.Main", new DropdownField('Country','Country',$array),'Content');

Avatar
ayyurek

22 June 2010 at 2:31am Community Member, 41 Posts

I am glad you found :) Yes, the third parameter is the value.

Avatar
bebabeba

22 June 2010 at 4:05am Community Member, 192 Posts

and if I need a dropdown in which I can select multiple choices?