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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Customising the CMS /

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

Populating CMS field with a dropdown of enum values


Go to End


3 Posts   13281 Views

Avatar
Andrew Houle

Community Member, 140 Posts

19 December 2008 at 10:02am

I'm trying to put together a simple page type that will have a dropdown of days of the week that is pulled from a set of enum values. Here is my code thus far:

<?php

class EveningPage extends Page {
	
	static $db = array(
		'Day' => "Enum('Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday','Monday')",
		'StartDate' => 'Date',
		'EndDate' => 'Date',
		'Comments' => 'Text'
	);
	
	function getCMSFields() {
      	$fields = parent::getCMSFields();
	  
               //This is where I need help
	  	$fields->addFieldToTab('Root.Content.Main', new DropdownField(
  			'Day',
  			'Day of the Week:',
  			singleton('EveningPage')->dbObject('Day')->enumValues()
		),
		
		  
		  $fields->removeFieldFromTab("Root.Content.Main","Content"); //Remove the content field
	
		  return $fields;
   	}

}

class EveningPage_Controller extends Page_Controller {
		
}

?>

This is not working, and I'm sure I have some things screwy, but I couldn't find much in the way of documentation for this sort of thing. Can anyone help... thanks so much!

Avatar
jamesg

Community Member, 8 Posts

19 December 2008 at 12:17pm

Edited: 19/12/2008 12:20pm

I think this:

$fields->addFieldToTab('Root.Content.Main', new DropdownField(
  'Day',
  'Day of the Week:',
  singleton('EveningPage')->dbObject('Day')->enumValues()
), 

Should be:
$fields->addFieldToTab('Root.Content.Main', new DropdownField(
  'Day',
  'Day of the Week:',
  singleton('EveningPage')->dbObject('Day')->enumValues()
));

That's the only thing I noticed.

Avatar
Andrew Houle

Community Member, 140 Posts

20 December 2008 at 3:34am

That did the trick. Thanks for taking the time to look that over!