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.

Customising the CMS /

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

[Solved] Problem adding new field to page


Go to End


3 Posts   1863 Views

Avatar
Avatar8

Community Member, 8 Posts

16 January 2010 at 7:23am

Edited: 17/01/2010 4:57am

Hi. I've got a strange problem. I've been adding fields to my page classes via their PHP files, and now I can't anymore. Basically, if I add a new field on ANY page and do a build (dev/build/) I get an incomplete log page, and accessing the site results in a blank page. If I remove the lines of code that I just entered, the build goes forward and the site works again. Here's the specific code I'm changing:

Initial code:

class HomePage extends Page {
   static $db = array(
   'HomeTitle' => 'Varchar(50)'
   );
	static $has_one = array(
      'FeatImage' => 'Image'
   );
	
   function getCMSFields() {
      $fields = parent::getCMSFields();
	
      $fields->addFieldToTab("Root.Content.Images", new ImageField('FeatImage'));
      $fields->addFieldToTab('Root.Content.Main', new TextField('HomeTitle'), 'Content');
      return $fields;
   }
}

Nonworking code with new field definition:

class HomePage extends Page {
   static $db = array(
   'HomeTitle' => 'Varchar(50)'
   'HomeSubtitle' => 'Varchar(50)'
   );
	static $has_one = array(
      'FeatImage' => 'Image'
   );
	
   function getCMSFields() {
      $fields = parent::getCMSFields();
	
      $fields->addFieldToTab("Root.Content.Images", new ImageField('FeatImage'));
      $fields->addFieldToTab('Root.Content.Main', new TextField('HomeSubtitle'), 'Content');
      $fields->addFieldToTab('Root.Content.Main', new TextField('HomeTitle'), 'Content');
      return $fields;
   }
}

I'm just following the prescribed format, and have successfully added multiple forms to other pages this way. Any ideas?

Thanks
-PM

EDIT: Given the place that the build log page ends, it looks like the build is hanging on creating the tables for the HomePage. Not sure why this would be happening...

Avatar
Willr

Forum Moderator, 5523 Posts

16 January 2010 at 4:58pm

I think its probably because you have a syntax error -

static $db = array( 
'HomeTitle' => 'Varchar(50)' 
'HomeSubtitle' => 'Varchar(50)' 
);

Is missing the ',' inbetween the array entries. It should be something like

static $db = array( 
'HomeTitle' => 'Varchar(50)',
'HomeSubtitle' => 'Varchar(50)' 
);

If you have php's display_errors set to on and devmode enabled then you should be getting semi helpful error messages including line numbers.

Avatar
Avatar8

Community Member, 8 Posts

17 January 2010 at 4:56am

Yep. That was it. Silly little syntax errors...

BTW, thanks for the info on the php dev mode. I'm still fairly new at this, so these little tricks are pretty valuable:)

thanks again.