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

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


Reply

3 Posts   703 Views

Avatar
theGermaniac

25 January 2010 at 8:39pm (Last edited: 25 January 2010 8:39pm), Community Member, 82 Posts

Hi,

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();
      
      $fields->addFieldsToTab(
         "Root.Content.Teaser",
         array(
            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

Avatar
theAlien

26 January 2010 at 2:20pm (Last edited: 26 January 2010 2:24pm), Community Member, 131 Posts

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 [url=http://doc.silverstripe.org/doku.php?id=data-types]docs[/url].
For more on relationships, please read the [url=http://doc.silverstripe.org/doku.php?id=tutorial:5-dataobject-relationship-management]fifth tutorial[/url]

Avatar
theGermaniac

26 January 2010 at 8:55pm Community Member, 82 Posts

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