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

WebService & Data Output


Go to End


3 Posts   1091 Views

Avatar
sherlackpr

Community Member, 2 Posts

6 May 2015 at 10:16am

Hi,

I'm developing a silverstripe + angularjs app. I'm creating a web service based on the restfulserver module that given a resource url it returns the data for that url.

Here is a snipped of the function that returns the data (http://pastebin.com/EUQPfkwQ).

I need to expose a web service with the following structure (http://pastebin.com/iAG0YCDK).

I need to know how to get the sitetree object related data in code.
Ej. Background field, background color, Gallery images related to the page.

Here is an example of my Page Class (http://pastebin.com/GNEeQSe3)

Attached Files
Avatar
Devlin

Community Member, 344 Posts

6 May 2015 at 7:34pm

Edited: 06/05/2015 7:35pm

I'm not sure I understood you correctly, but I hope this helps...

I need to know how to get the sitetree object related data in code.

$page = SiteTree::get_by_link($segment);
// db
echo $page->showGallery; // Boolean
echo $page->bgColor; // VarChar(7)
// has_one
echo $page->BackgroundID; // Int
echo $page->Background(); // Image DataObject
echo $page->Background()->Filename; // String
// has_many
echo $page->GalleryImages(); // DataList
foreach($page->GalleryImages() as $item) {
	echo $item; // GalleryImage DataObject
	// has_one
//	echo $item->ImageID; // Int
//	echo $item->Image(); // Image DataObject
//	echo $item->Image()->Filename; // String
}

Avatar
sherlack

Community Member, 10 Posts

2 June 2015 at 1:51am

Hi, Thanks for your help Devlin. That worked!!!