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

Updating field value and update


Go to End


5 Posts   1564 Views

Avatar
swaiba

Forum Moderator, 1899 Posts

26 November 2009 at 2:30am

Hi,

I have code that is as follows...

$childObject = DataObject::get_by_id($this->sourceClass, $ID);
$childObject->myfield = $new_data;
$childObject->write();

and the $new data is not getting to the written back to the database.

I have tried $childObject->forceChange(); before the write and tried $childObject->write(false,false,true); to force the write to write... I have also output the $childObject->myfield after being set and can confirm $new_data is in there...

...what else can I do to ensure I write this data back?

Any help much appreciated.

Barry

Avatar
swaiba

Forum Moderator, 1899 Posts

26 November 2009 at 3:32am

Arrrrggh! This is my third thread and replied to all of them fixing them soon after raising it.

Turns out 'myfield' in $childObject->myfield = $new_data; was spelt incorrectly and there is no failure, no report of setting a field that doesn't exist... I guess this is a great feature that I did not know about!

Next time maybe I'll need some help from you guys!

Barry

Avatar
dalesaurus

Community Member, 283 Posts

26 November 2009 at 4:47am

No no no, self help is good! Glad you got it sorted out, I know I'd do this all the time if it wasn't for auto-complete in NetBeans.

Avatar
swaiba

Forum Moderator, 1899 Posts

26 November 2009 at 5:06am

Thanks Dale, I am using Notepad++ with an FTP plugin at the moment... not the best IDE... I was (as soon as a new project starts up) start going to use PHPEclipse with code completion, goto declaration and debugging... how would that compare with NetBeans?

Avatar
dalesaurus

Community Member, 283 Posts

26 November 2009 at 6:45am

They are very similar in capabilities. I prefer NetBeans because all the goodies (SVN, SQL browser, xdebug) are part of the core platform, and Eclipse always makes me install a dozen plugins to get it to a usable state.

Both will be a great improvement over your current setup. More at http://doc.silverstripe.org/doku.php?id=tools