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

How to use data from a DataObject::get or DataObject::get_one result in code?


Go to End


3 Posts   1465 Views

Avatar
Double-A-Ron

Community Member, 607 Posts

22 September 2010 at 12:09pm

Quite simple really:

$record = DataObject::get('Subdomain',"Subdomain='$subdomain' AND Status=1");
echo 'data=' . $record->ID;
die();

The above code returns nothing, although

print_r($record);

displays a full recordset as expected.

How do I access individual values from the recordset returned by DataObject::get? I have tried every field name available for the above object. None display anything despite there being data in the recordset.

Aaron

Avatar
Martijn

Community Member, 271 Posts

22 September 2010 at 12:58pm

if($records = DataObject::get('Subdomain',"Subdomain='$subdomain' AND Status=1")){

foreach($records as $record){
echo $record->Title.'<br />';
}

}

Avatar
Double-A-Ron

Community Member, 607 Posts

22 September 2010 at 1:01pm

Yeah I just figured that out and used get_one instead. I should have known get() would return a collection and I was treating it as a single resultset.

Thanks
Aaron