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.

Customising the CMS /

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

Get Image URL of DataObject


Go to End


1323 Views

Avatar
darwin

Community Member, 6 Posts

13 December 2013 at 11:05am

My DataObject has one Image.

I want to display the DataObject in JSON. In addition, I want to add the Image.Filename to the JSON Array.

$query = "SELECT * FROM Object LEFT JOIN File ON Object.ImageID = File.ID";
$records = DB::query($query);
return $f->convertDataObjectSet($records);

I guess that the $records object is no DataObjectSet, so JSON does not work. Although it works when doing DataObject::get("Object)!

Could you please tell me how to convert the $records object to JSON? (Or is there a better way of doing this?)

Thank you!