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.

General Questions /

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

can't get image Class in Page_Controller


Reply


3 Posts   1679 Views

Avatar
mtz

Community Member, 17 Posts

14 March 2010 at 7:32am

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

Avatar
Mo

Community Member, 514 Posts

14 March 2010 at 9:54am

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

Avatar
mtz

Community Member, 17 Posts

15 March 2010 at 12:00am

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