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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Adding NumericField()


Go to End


3 Posts   1433 Views

Avatar
VirtuallyUknown

Community Member, 4 Posts

12 March 2010 at 6:29pm

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.

Avatar
Mo

Community Member, 541 Posts

14 March 2010 at 9:57am

You should just have to use:

$Quarter01visitor

In your template.

Mo

Avatar
Mo

Community Member, 541 Posts

14 March 2010 at 10:00am

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