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.

Data Model Questions /

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

siteConfig DataExtension not saving, no default values


Go to End


2 Posts   1502 Views

Avatar
Bimble

Community Member, 16 Posts

22 December 2013 at 3:59am

Edited: 22/12/2013 4:00am

Hi, I am trying to extend DataExtension, but the default values are not being displayed and any values are not being saved to the DB.

 <?php

class AnalyticsConfig extends DataExtension {

  private static $db = array(
    'redisIP' => 'varchar(250)',
    'redisPort' => 'varchar(250)',
    'redisSize' => 'varchar(250)',
  );

  public static $defaults = array(
    'redisIP' => '127.0.0.1',
    'redisPort' => '6379',
    'redisSize' => '4832',
  );

  public function updateCMSFields(FieldList $fields) {
    $fields->addFieldToTab("Root.Main", new TextField("RedisIP", "Redis IP"));
    $fields->addFieldToTab("Root.Main", new TextField("RedisPort", "Redis Port"));
    $fields->addFieldToTab("Root.Main", new TextField("RedisSize", "Redis Size"));
  }

}

also, in _config.php i added

Object::add_extension('SiteConfig', 'AnalyticsConfig');

Any ideas?

Avatar
swaiba

Forum Moderator, 1899 Posts

24 December 2013 at 12:16am

Hi,

Please see http://api.silverstripe.org/3.1/class-DataExtension.html

Alternatively if you are not using 3.1 then look for older documentation. Also look at several small modules as these often have great examples of exending the silverstripe datamodel