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

PopulateDefault a DataObjectManager List


Go to End


1262 Views

Avatar
eceers

Community Member, 24 Posts

14 March 2010 at 12:13pm

Hi,

My client has a need to be able to build a DataObjectManager list of default values.

I thought I was going to be able to use something like;

	public static $db = array(
		'TextBox1' => 'Text',
		'TextBox2' => 'Text',
		'TextBox3' => 'Text'		
	);
	
	public static $has_many = array(
		'ProjectFields1' => 'ProjectField'
	);
	
	public function populateDefaults() { 
	   	$this->TextBox1 = 'Eggs Are Great';
	   	$this->TextBox2 = 'Patty is a winner';
		$this->TextBox3 = 'Maya steps very loudly';
		
		$this->ProjectFields1 = array(
			array(
				'Title'=>'Question 01', 
				'Description'=>'Lorem ipsum dolor sit amet, consectetur adipisicing elit.'
				),
			array(
				'Title'=>'Question 02', 
				'Description'=>'Lorem ipsum dolor sit amet, consectetur adipisicing elit.'
				)	
			);	
	   parent::populateDefaults(); 
	}

but no luck :(

The DataObject I'm using looks like

class ProjectField extends DataObject {

	static $db = array(
		'Title' => 'Text',
		'Description' => 'HTMLText',
	);

	static $has_one = array(
	   	'ProjectField' => 'GeneralPage',
	);

	function getCMSFields_forPopup() {
		$fields = new FieldSet();
		$fields->push( new TextField( 'Title' ) );
		$fields->push( new SimpleWysiwygField('Description'));
   		return $fields;
	}	
}

Two questions I suppose, am I heading in the right direction? if so could possibly help me over the edge?

Second, is it all possible? I would of thought so.

Any help would be greatly appreciated.