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

adding new field to page module


Go to End


2 Posts   1271 Views

Avatar
jaybee

Community Member, 49 Posts

20 May 2010 at 9:16am

Hey all,

I've added a new field to the mysite/code/Page.php file and it built fine, but when I try to populate the field with data in the admin area it says it updates but doesn't save the data to the database table. Have I setup the code correctly? Sound like anything obvious?

class Page extends SiteTree {
	
	public static $db = array(
	);
	
	public static $has_one = array(
		'GoogleMapAddress' => 'Text'
	);
	
	public function getCMSFields() {
		$fields = parent::getCMSFields();

		$fields->addFieldToTab('Root.Content.Main', new TextField('GoogleMapAddress', 'Google Map Address'), 'Content');

		return $fields;
	}
}

Thanks

Avatar
Juanitou

Community Member, 323 Posts

20 May 2010 at 10:18am

Hi!

You have not added a field (db array), but a relation (has-one array), with a wrong syntax, by the way. Just put 'GoogleMapAddress' => 'Text' in the db array.

May I suggest you to follow the SS tutorials? You’ll quickly get it.

Hope it helps,
Juan