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

[solved] accessing $Photo in controller class


Go to End


3 Posts   1979 Views

Avatar
marcink

Community Member, 89 Posts

28 March 2011 at 8:51pm

Edited: 28/03/2011 9:13pm

hi,
i have added an image in the model:

public static $has_one = array(
	"Photo" => "Image"
);

how can i access it from controller?

when i call

print_r($this)
in controller, i can see the reference to the photo in the listing, but i can't find a way to access it.

when i try

$this->Photo
i get an undefined.
but accessing any other custom entry from static db array
public static $db = array(
	"Abstract" => "Text",
	"Phone1" => "Text",
	"Phone2" => "Text"
);

works.

so, is there a way to access $Photo?

Avatar
Willr

Forum Moderator, 5523 Posts

30 March 2011 at 12:01am

You need to use the method syntax for accessing relationships like that - $this->Photo(); to get the image record.

Avatar
marcink

Community Member, 89 Posts

1 April 2011 at 7:11am

thanks! i still sometimes fight with php... :)