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.

General Questions

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

Problem adding fields to custom module


3 Posts   750 Views


11 April 2009 at 6:53am Community Member, 4 Posts

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:

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


11 April 2009 at 4:45pm Forum Moderator, 5511 Posts

'jobDescription' => 'Text'

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


11 April 2009 at 6:52pm Community Member, 4 Posts

Thanks! I totally overlooked that.