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.

Data Model Questions /

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

write function result to dataobject


Go to End


2 Posts   1489 Views

Avatar
voodoochile

Community Member, 52 Posts

13 June 2014 at 10:08pm

Hi There

I am a little stuck at the moment, I have a function (this works ok) that looks like this.

 
            function Addab()
             {
                $a = 1
                $b = 2
                $c = $a+$b;
                return $c;
              }

my question is how can i get the result and write it to a field in another dataobject?

any help or ideas would be appereciated thank you

Avatar
Willr

Forum Moderator, 5523 Posts

28 June 2014 at 8:06pm

How you get the result of that depends on where that function is and where you want to write the dataobject?

To update a dataobject it's a simple task of getting the object, setting the property and calling write()

$obj = Page::get()->first();
$obj->Title = "Test";
$obj->write();