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.

Archive

Our old forums are still available as a read-only archive.

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

addFieldToTab help


Reply

3 Posts   5458 Views

Avatar
McSwain

3 April 2008 at 3:49pm Community Member, 4 Posts

I'm working through the tutorials, trying to make a website that would catalog registered horses and cattle with long pedigrees. I added an AnimalPage that looks like:

class AnimalPage extends Page {
static $db = array(
   'BirthYear' => 'Int',
   'Coloring' => 'Varchar',
   'Sex' => 'Varchar',
   'Price' => 'Currency',
   'Pedigree1' => 'Varchar',
   'Pedigree2' => 'Varchar',
   'Pedigree3' => 'Varchar',
   'Pedigree4' => 'Varchar',
   'Pedigree5' => 'Varchar',
   'Pedigree6' => 'Varchar',
   'Pedigree7' => 'Varchar',
   'Pedigree8' => 'Varchar',
   'Pedigree9' => 'Varchar',
   'Pedigree10' => 'Varchar',
   'Pedigree11' => 'Varchar',
   'Pedigree12' => 'Varchar',
   'Pedigree13' => 'Varchar',
   'Pedigree14' => 'Varchar',
   'ShortDescrip' => 'HTMLText'
);

static $has_one = array(
);

function getCMSFields() {
   $fields = parent::getCMSFields();

$fields->addFieldToTab('Root.Content.Main', new NumericField('BirthYear'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Coloring'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Sex'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new CurrencyField('Price'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Pedigree1'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Pedigree2'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Pedigree3'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Pedigree4'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Pedigree5'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Pedigree6'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Pedigree7'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Pedigree8'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Pedigree9'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Pedigree10'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Pedigree11'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Pedigree12'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Pedigree13'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Pedigree14'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('ShortDescrip'), 'Content');
   
return $fields;
}

}

class AnimalPage_Controller extends Page_Controller {

}

where $Pedigree# would be one of the animal's pedigree. I don't understand why only coloring sex and price are working. Also, in tutorial 2 where they do this, they add Date and Author. What do you do if you want the title in the CMS to say something more descriptive, like "Enter the birth year (yyyy)". I tried

$fields->addFieldToTab('Root.Content.Main', new NumericField('BirthYear'), 'Content') ->describe("Enter the birth year (yyyy)");

which returned an error on the describe funtion. Any help would be appreciated.

Avatar
Willr

3 April 2008 at 8:28pm (Last edited: 3 April 2008 8:29pm), Forum Moderator, 5511 Posts

What do you do if you want the title in the CMS to say something more descriptive, like "Enter the birth year (yyyy)"...

Field types have a second parameter you can use - which is title. By default it just uses the ID (the first argument) but you can override this with a second one so for your example you can have

new NumericField('BirthYear','Enter the birth year (yyyy)'), 'Content');

As for the the Pedigree issue - you might want to look at using a HasManyComplexTable field instead of the current setup - http://doc.silverstripe.com/doku.php?id=hasmanycomplextablefield.

I have no idea why they are not displaying in the cms as it is though..

EDIT: typo spotted!

Avatar
McSwain

4 April 2008 at 1:29pm Community Member, 4 Posts

Hey thanks for the tip. The fields started working, I'm not sure what I did to get it going; probably something to do with kicking my computer.