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

Copying Data from DataObject to Member

Go to End

2 Posts   1348 Views


Community Member, 545 Posts

28 August 2009 at 10:21am

I have UserApplication for that I want to move the Data to a Member Group once the User is approved, however I'm having trouble writing to the Member Class, I think its because I have Extra KEys and I need to match them up

Here is the DataObject Containing the Unapproved Member

class UserApplication extends DataObject {
	static $db = array(
			'FirstName' => 'Text',
			'Surname' => 'Text',
			'Email' => 'Text',
			'CompanyName' => 'Text',
			'CompanyType' => "Text",
			'CompanyURL' => 'Text',
			'HomePhone' => 'Text',
			'Address' => 'Text',
			'AddressLine2' => 'Text',
			'City' => 'Text',
			'Country' => 'Text',
			'TaxIDNumber' => 'Text',
			'Distributor' => 'Text',
			'SalesRep' => 'Text',
			'Notes' => 'Text',
			'ApprovedMember' => 'Boolean',
			'Password' => 'Text'
	static $has_one = array(
		'RegistrationPage' => 'RegistrationPage',		   
	public function getCMSFields_forPopup()
		$companyTypeList = array(
			'Retail' => 'Retail',
			'Online' => 'Online',
			'Distributor' => 'Distributor',
			'Press' => 'Press'
		return new FieldSet (
			new CheckBoxField('ApprovedMember', 'Approved Member'),
			new TextField('FirstName', 'First Name'),
			new TextField('Surname','Last Name'),
			new EmailField('Email'),
			new TextField('CompanyName','Company Name'),
			new DropdownField('CompanyType','Company Type',$companyTypeList),
			new TextField('CompanyURL','Company Website'),
			new TextField('HomePhone','Company Phone'),
			new TextField('Address','Address'),
			new TextField('AddressLine2','Address Line 2'),
			new TextField('City','City'),
			new TextField('Country','Country'),
			new TextField('TaxIDNumber','TaxIDNumber'),
			new TextField('Distributor','Distributor'),
			new TextField('SalesRep','Sales Rep'),
			new TextareaField('Notes','Description'),
			new ConfirmedPasswordField('Password')

And here is the CMS function writing to the Member Class

class ApplicationDataObjectManager extends DataObjectManager 
   public $popupClass = "ApplicationDataObjectManager_Popup"; 
   public $itemClass = "ApplicationDataObjectManager_Item";


class ApplicationDataObjectManager_Popup extends DataObjectManager_Popup 
function __construct($controller, $name, $fields, $validator, $readonly, $dataObject) { 
parent::__construct($controller, $name, $fields, $validator, $readonly, $dataObject); 
new FormAction('ApproveUser','Approve User') 

   function ApproveUser($data, $form, $request) { 
// do stuff 
	 	$member = new Member();
		$groupID = 2;
		switch ($member->CompanyType) {
			case ("Retail"): $groupID = 3;
			case ("Distributor"): $groupID = 4;
			case ("Press"): $groupID = 5;
			case ("Online"): $groupID = 6;
		if($group = DataObject::get_one('Group', "ID = 2")) { 
			return print_r($member);	
			return print_r($member->ID);	


class ApplicationDataObjectManager_Item extends DataObjectManager_Item 



Community Member, 288 Posts

29 August 2009 at 2:16am

I see that you're extending the DataObjectManager module by Uncle Cheese. If you haven't done so already then you should ask your question inte DataObjectManager forum. Uncle Cheese is quick on the replies so I bet you'll get help there.

Also it would be really good to know what actually happens when you try to write to the member class.