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.

Customising the CMS /

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

Display the ID


Go to End


2 Posts   1327 Views

Avatar
landyman

Community Member, 11 Posts

17 October 2010 at 7:46pm

Hello -
How can I display the ID assigned to the current DataObject in the admin. I've tried adding fields and making them readonly, but the fields never show up; something like:
$fields->addFieldToTab("Root.Content.Main", new TextField("ID", "Doctor ID"));

the field doesn't show up. Is there a way I can display that info in the admin?

Thanks!

-Aaron

Avatar
swaiba

Forum Moderator, 1899 Posts

19 October 2010 at 9:56pm

Hi,

This will show the ID in the list of records and in the record view. I have found that using 'known' names for fields doesn't always work - so in this case I make sure that I am not using the name 'ID' instead 'MyID'.

public static $summary_fields = array (
	'ID' => 'ID',
	...
);

...

function getCMSFields()
{
	$fields = parent::getCMSFields();

	$fields->insertBefore(new TextField('MyID','MyID',$this->ID),'Name');

	return $fields;
}

(note assumes 'Name' in your $db fields!)