10678 Posts in 2792 Topics by 1518 members
Jump to:If this is your first visit, you will need to register before you can post. However, you can browse all messages below.
| Page: 1 | go to end | Reply | |
| Author | Topic: addFieldToTab help | 567 views |

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.

3 April 2008 at 8:28pm
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!
Last edited: 3 April 2008 at 8:29pm

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.
| 567 views | |||
| go to top | Reply |