Jump to:

23493 Posts in 19013 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Adding NumericField()

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

Page: 1
Go to End
Author Topic: 1016 Views
  • VirtuallyUknown
    Avatar
    Community Member
    4 Posts

    Adding NumericField() Link to this post

    Relatively new to Silverstripe, and loving it. Starting to try to add some more functional pages. And not much experience in php.

    I'm making a site for a local football team. I have everything showing up in cms and on the web page. So I know my numbers are good from the CMS to the db to the web page.

    I want to be able to add the scores for the quarters.

    Here is how I have it set up in php page.

    'Quarter01visitor' => 'Int',
    .....
    .....

    $fields->addFieldToTab("Root.Content.Box", new NumericField("Quarter01visitor", "1st Quarter - Visiting Team"));
    .....
    .....

    How can I add up my Quarter01visitor, Quarter02visitor...etc... into a new variable to display on my page?
    Am I on the right track?

    Thanks for any help.

  • Mo
    Avatar
    Community Member
    508 Posts

    Re: Adding NumericField() Link to this post

    You should just have to use:

    $Quarter01visitor

    In your template.

    Mo

  • Mo
    Avatar
    Community Member
    508 Posts

    Re: Adding NumericField() Link to this post

    Oops, just read your post again, sorry. You are probably best off using a custom method in your Page_Controller. Something like:

    ...
    public function getQuarterTotal() {
    return ($this-> Quarter01visitor + $this->Quarter02visitor);
    }
    ...

    Then add:

    $QuarterTotal

    to your template

    Mo

    1016 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.