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   5529 Views

Avatar
McSwain

Community Member, 4 Posts

3 April 2008 at 3:49pm

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

Forum Moderator, 5513 Posts

3 April 2008 at 8:28pm

Edited: 03/04/2008 8:29pm

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

Community Member, 4 Posts

4 April 2008 at 1:29pm

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.