Jump to:

5513 Posts in 1732 Topics by 1218 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Backend inputs won't be saved... at least not all

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

Page: 1
Go to End
Author Topic: 688 Views
  • theGermaniac
    Avatar
    Community Member
    82 Posts

    Backend inputs won't be saved... at least not all Link to this post

    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

  • theAlien
    Avatar
    Community Member
    131 Posts

    Re: Backend inputs won't be saved... at least not all Link to this post

    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

  • theGermaniac
    Avatar
    Community Member
    82 Posts

    Re: Backend inputs won't be saved... at least not all Link to this post

    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

    688 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.