Jump to:

23371 Posts in 18161 Topics by 2865 members

General Questions

SilverStripe Forums » General Questions » can't get image Class in Page_Controller

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: 1589 Views
  • mtz
    Avatar
    Community Member
    17 Posts

    can't get image Class in Page_Controller Link to this post

    I'm a little bit confused about the way I used to get the Image - Class in Page Controller.

    in older Silverstripe - installations i got the Image that i defined in Page-Class via:

    class Page_Controller extends ContentController {

    $actPage = DataObject::get_by_id("Page", $this->ID);
    return $actPage->Image()->CroppedImage(100, 100);

    }

    im an actual installation i get an Exception: Object->__call(): the method 'image' does not exist on 'Page'

    'image does not exist on Page' ?!

    can anyone Help?

    thanks

  • Mo
    Avatar
    Community Member
    505 Posts

    Re: can't get image Class in Page_Controller Link to this post

    Hi mtz,

    What version of SS are you using? Is your $has_one association called 'Image'? If not, then the method you need to call is the Association name.

    Usually, if I want to retrieve an Image, I use:

    DataObject::get_by_id('Image',$this->HasOneName()->ID);

    Not sure if that is the best way, but it seems to work.

    Mo

  • mtz
    Avatar
    Community Member
    17 Posts

    Re: can't get image Class in Page_Controller Link to this post

    Hi Mo,

    thanks! You gave me the right hint.

    my has_one relation is:

    static $has_one = array(
          'SectionImage' => 'Image'
       );

    so i have to call $this->SectionImage();

    greets,

    Mtz

    1589 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.