Jump to:

23473 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Problem adding fields to custom module

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 741 Views
  • RickT
    Avatar
    Community Member
    4 Posts

    Problem adding fields to custom module Link to this post

    I'm creating a module to handle employee information. When I create a 'jobDescription' field in my staffPage.php, it creates a jobDescriptionID field in the database and, of course, doesn't save my text value.

    The code for the staffPage.php is:

    <?php
    class StaffPage extends Page {
    static $db = array(
    );
    static $has_one = array(
       'jobDescription' => 'Text',
       'colorPhoto' => 'File',
       'bwPhoto' => 'File'
    );
    function getCMSFields() {
       $fields = parent::getCMSFields();
       $fields->addFieldToTab("Root.Content.Main", new TextField('jobDescription', 'Job description'), 'Content');
       $fields->addFieldToTab("Root.Content.Main", new FileIFrameField('colorPhoto', 'Color photo'), 'Content');
       $fields->addFieldToTab("Root.Content.Main", new FileIFrameField('bwPhoto', 'Black & white photo'), 'Content');
       $fields->renameField("Title", "Name");
       $fields->renameField("Content", "Bio");
       return $fields;
    }
    }
    class StaffPage_Controller extends Page_Controller {

    }
    ?>

    I'm using 2.30rc3.

    Thanks in advance, Rick

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Problem adding fields to custom module Link to this post

    'jobDescription' => 'Text'

    This is a Text Field, not a Relationship so it should be in the $db array and not the $has_one array

  • RickT
    Avatar
    Community Member
    4 Posts

    Re: Problem adding fields to custom module Link to this post

    Thanks! I totally overlooked that.

    Rick

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