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.

General Questions

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

Adding NumericField()


Reply

3 Posts   1024 Views

Avatar
VirtuallyUknown

12 March 2010 at 6:29pm Community Member, 4 Posts

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

14 March 2010 at 9:57am Community Member, 509 Posts

You should just have to use:

$Quarter01visitor

In your template.

Mo

Avatar
Mo

14 March 2010 at 10:00am Community Member, 509 Posts

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