Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » addFieldToTab help

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

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

Page: 1
Go to End
Author Topic: 5420 Views
  • McSwain
    Avatar
    Community Member
    4 Posts

    addFieldToTab help Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: addFieldToTab help Link to this post

    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!

  • McSwain
    Avatar
    Community Member
    4 Posts

    Re: addFieldToTab help Link to this post

    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.

    5420 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.