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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Equivalent of <% control * %> and <% if * %> in Page_Controller


Go to End


3 Posts   1759 Views

Avatar
dynamite

Community Member, 66 Posts

3 April 2009 at 2:41am

Another noob question that I am not sure if I am even phrasing correctly!

What is the equivalent of <% control Page(home) %> and <% if BannerImage.PageBanner %> when working inside "Page_Controller extends ContentController"?

I am working through the tutorial at

http://doc.silverstripe.com/doku.php?id=imageupload

and would like to access the data/object before the view/template.

Thank you!

Avatar
Hamish

Community Member, 712 Posts

7 April 2009 at 8:50pm

Hi hi,

What is the equivalent of <% control Page(home) %>...

That is a bit like calling:

$obj = DataObject::get_one('Page', "URLSegment = 'Home'");

$obj would be the object you are 'controlling'.

...and <% if BannerImage.PageBanner %>

This would be equivalent to:

if($this->BannerImage) {
	// do stuff
}

Note that I don't need to use the 'PageBanner', as 'PageBanner' is a method on the 'BannerImage' object. If 'BannerImage' exists, we can assume that $this->BannerImage->PageBanner() will exist.

Hopefully this helps :)

Regards,
Hamish

Avatar
dynamite

Community Member, 66 Posts

14 April 2009 at 12:22am

Yes, that is very helpful! Thank you.