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.

Customising the CMS /

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

Backend inputs won't be saved... at least not all

Go to End

3 Posts   896 Views


Community Member, 107 Posts

25 January 2010 at 8:39pm

Edited: 25/01/2010 8:39pm


I extended the backend with a new Main.Teaser tab and created an ImageField, two TextFields and and a SiteTree DropDown. Perfectly working are the Image and the DropDown. The TextFields are shown, but the data cannot be saved, that means, you can write text in it, can save the site, get a positive feedback "Your site has been saved.", but when you reload the backend site, the information is gone... Strange, isn't it?

Here is my code:

class TeaserContentCombo extends Page {
	static $db = array();
	static $has_one = array(
		'TeaserPhoto' => 'Image',
		'TeaserTitle' => 'Text',
		'TeaserContent' => 'Text',
		'TeaserTarget' => 'SiteTree'
	function getCMSFields() {
		$fields = parent::getCMSFields();
				new ImageField('TeaserPhoto'),
				new TextField('TeaserTitle'),
				new TextField('TeaserContent'),
				new TreeDropdownField("TeaserTargetID", "Choose a site to be forwarded to:", "SiteTree")
		return $fields;

class TeaserContentCombo_Controller extends Page_Controller {

Thanks a ton for every help in advance!

Cheers, Mario


Community Member, 131 Posts

26 January 2010 at 2:20pm

Edited: 26/01/2010 2:24pm

Ah... you got me there: staring and staring at your code...

But actually it is quite simple.
Both TeaserTitle and TeaserContent should be in the $db-array since Text is a data-type on the TeaserContentCombo-table.

Instead of being a data-type, Image and SiteTree mean that TeaserPhoto and TeaserTarget are establishing a relationship with either the Image- and the SiteTree-table (same for $has_many and $many_many).

In general: all data-types should be in the $db-array, all relationships in $has_one, $has_many and $many_many.
For more on data-types, please read the docs.
For more on relationships, please read the fifth tutorial


Community Member, 107 Posts

26 January 2010 at 8:55pm

Thanks! Thanks! Thanks!

I found that out by myself, but I was hoping, that someone will give me an explanation about why. And you did this perfect! Thank you!

Cheers, Mario