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

Accessing DataObject properties inside a controller


Go to End


2 Posts   985 Views

Avatar
NicolasLeuenberger

Community Member, 11 Posts

29 September 2014 at 7:23am

Hi there

I don't understand how (and if?) I can access a DataObject's properties inside the controller.
I've got a shopping cart page and products that have a property "Price". I can populate the shopping cart and read the product's "Price"-property in the template, that's no problem. But how do I add the prices of the different products? I have to do that inside the controller and none of these work:

$item->Price, $item->Price()

I also tried writing a getPrice-function into the DataObject, but that doesn't work either. Does anybody know what I'm doing wrong?

Thanks for your help!
Nico

Avatar
micmania1

Community Member, 9 Posts

30 September 2014 at 2:14pm

$item->Price should work.

You may have to provide more code.