21286 Posts in 5733 Topics by 2602 members
General Questions
SilverStripe Forums » General Questions » How to use data from a DataObject::get or DataObject::get_one result in code?
General questions about getting started with SilverStripe that don't fit in any of the categories above.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 882 Views |
-
How to use data from a DataObject::get or DataObject::get_one result in code?

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
-
Re: How to use data from a DataObject::get or DataObject::get_one result in code?

22 September 2010 at 12:58pm
if($records = DataObject::get('Subdomain',"Subdomain='$subdomain' AND Status=1")){
foreach($records as $record){
echo $record->Title.'<br />';
}}
-
Re: How to use data from a DataObject::get or DataObject::get_one result in code?

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
| 882 Views | ||
|
Page:
1
|
Go to Top |


