Jump to:

5514 Posts in 1733 Topics by 1219 members

Customising the CMS

SilverStripe Forums » Customising the CMS » adding new field to page module

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

Page: 1
Go to End
Author Topic: 894 Views
  • netnerd85
    Avatar
    Community Member
    42 Posts

    adding new field to page module Link to this post

    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

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: adding new field to page module Link to this post

    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

    894 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.