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

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


Reply


3 Posts   1084 Views

Avatar
Double-A-Ron

Community Member, 604 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, 604 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