Jump to:

5537 Posts in 1737 Topics by 1223 members

Customising the CMS

SilverStripe Forums » Customising the CMS » [Solved] Problem adding new field to page

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

Page: 1
Go to End
Author Topic: 1253 Views
  • Avatar8
    Avatar
    Community Member
    8 Posts

    [Solved] Problem adding new field to page Link to this post

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

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: [Solved] Problem adding new field to page Link to this post

    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.

  • Avatar8
    Avatar
    Community Member
    8 Posts

    Re: [Solved] Problem adding new field to page Link to this post

    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.

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