Jump to:

23480 Posts in 18951 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » [solved] accessing $Photo in controller class

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

Page: 1
Go to End
Author Topic: 1207 Views
  • marcink
    Avatar
    Community Member
    89 Posts

    [solved] accessing $Photo in controller class Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5502 Posts

    Re: [solved] accessing $Photo in controller class Link to this post

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

  • marcink
    Avatar
    Community Member
    89 Posts

    Re: [solved] accessing $Photo in controller class Link to this post

    thanks! i still sometimes fight with php...

    1207 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.