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:

Archive /

Our old forums are still available as a read-only archive.

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

Extend Member using DataObjectDecorator

Go to End

6 Posts   4853 Views


Community Member, 22 Posts

3 December 2008 at 10:03am

Can anyone give me a code example or a link showing how to extend a member object to have additional fields using a DataObjectDecorator? As simple as you have got.


Community Member, 400 Posts

3 December 2008 at 3:20pm

check the forum's ForumRole.php


Community Member, 470 Posts

3 December 2008 at 6:12pm

Have you checked the docs? A lot of info in there.


Community Member, 22 Posts

6 December 2008 at 6:50am

In the ForumRole decorator there is reference to a table ForumMember in a function called augmentDatabase.

I don't see that table. What is this all about?

function augmentDatabase() {
		$exist =  DB::query( "SHOW TABLES LIKE 'ForumMember'" )->numRecords();
		if( $exist > 0 ) {
			DB::query( "UPDATE `Member`, `ForumMember` " .
				"SET `Member`.`ClassName` = 'Member'," .
				"`Member`.`ForumRank` = `ForumMember`.`ForumRank`," .
				"`Member`.`Occupation` = `ForumMember`.`Occupation`," .
				"`Member`.`Country` = `ForumMember`.`Country`," .
				"`Member`.`Nickname` = `ForumMember`.`Nickname`," .
				"`Member`.`FirstNamePublic` = `ForumMember`.`FirstNamePublic`," .
				"`Member`.`SurnamePublic` = `ForumMember`.`SurnamePublic`," .
				"`Member`.`OccupationPublic` = `ForumMember`.`OccupationPublic`," .
				"`Member`.`CountryPublic` = `ForumMember`.`CountryPublic`," .
				"`Member`.`EmailPublic` = `ForumMember`.`EmailPublic`," .
				"`Member`.`AvatarID` = `ForumMember`.`AvatarID`," .
				"`Member`.`LastViewed` = `ForumMember`.`LastViewed`" .
				"WHERE `Member`.`ID` = `ForumMember`.`ID`"
			echo("<div style=\"padding:5px; color:white; background-color:blue;\">" . _t('ForumRole.TRANSFERSUCCEEDED','The data transfer has succeeded. However, to complete it, you must delete the ForumMember table. To do this, execute the query \"DROP TABLE \'ForumMember\'\".') . "</div>" );


Community Member, 14 Posts

9 December 2008 at 11:59pm

I have a much simpler example:

class MyMemberExtension extends DataObjectDecorator {
	function extraDBFields() {
		return array(
			'db' => array(
			'has_one' => array(
				'Avatar' => 'Image'
	public function updateCMSFields(FieldSet &$fields) {
	   $fields->push(new TextField('Website', 'Website-URL'));
	   $fields->push(new ImageField('Avatar', 'Profile Image'));

In mysite/_config.php:

Object::add_extension('Member', 'MyMemberExtension');


Community Member, 22 Posts

10 December 2008 at 4:31am

Thanks for responding adiwidjaja.

That is a much simpler example. Also pointing out the _config.php inclusion is good too as this is how the system knows of the decorator's existence. The forum code takes days to ponder.

Do you happen to know what is going on in the ForumRole function augmentDatabase() and the ForumMember table reference?