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


Reply


3 Posts   766 Views

Avatar
RickT

Community Member, 4 Posts

11 April 2009 at 6:53am

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

Avatar
Willr

Forum Moderator, 5513 Posts

11 April 2009 at 4:45pm

'jobDescription' => 'Text'

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

Avatar
RickT

Community Member, 4 Posts

11 April 2009 at 6:52pm

Thanks! I totally overlooked that.

Rick