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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

[SOLVED] Population dropdown field with enum values


Go to End


9266 Views

Avatar
Tonyair

Community Member, 81 Posts

5 July 2010 at 3:01am

Edited: 05/07/2010 4:53am

Hello, I need to populate dropdown field with enum values I tried:

$this->dbObject('Status')->enumValues(); as described there http://doc.silverstripe.org/dropdownfield

class ContactPage extends Page {
	static $db = array(
...
		"Status" => "Enum('Active, Inactive')",
..
	);
	static $can_be_root = false;

	static $has_one = array(
		'Photo' => 'Image'
	);
 
	function getCMSFields() {
		$fields = parent::getCMSFields();
		$fields->addFieldToTab("Root.Content.Main",
						new FieldGroup(
						..
							new DropdownField('Status','Status',singleton('ContactPage')->dbObject('Status')->enumValues()),
..

But still getting error that there're no method enumValues

ERROR [User Error]: Uncaught Exception: Object->__call(): the method 'enumvalues' does not exist on 'Varchar'
IN POST /stable/admin/getitem?ID=42&locale=ru_RU&ajax=1
Line 724 in /home/a2nt/work/www/stable/sapphire/core/Object.php

[UPDATE]: SOLVED variable 'Status' reserved by SiteTree