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:

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

DataObject on Page but Not on Security Page


Go to End


3 Posts   836 Views

Avatar
zenmonkey

Community Member, 545 Posts

16 September 2009 at 7:00am

I have a DataObject attached to the Page Controller and a Custom Function to check it Exists in the Template, however it looks like Extra Dataobjects don't get attached to the CMS login pages and as such Generates an Error for a Malformed SQL query. Whats the BEst way to resolve this?

This is the Query in my Page Controller

function LifeStyleShot() {
		$result = DataObject::get("ExtraPageImages","Category = 'Lifestyle' AND PageID=".$this->ID);
		if($result) {
			return $result;
		}
		else {
			$backup = DataObject::get("ExtraPageImages","Category = 'Lifestyle' AND PageID=".$this->ParentID);
			if($backup) {
				return $backup;
			}
			else {
				return false;
			}
		}
	}

The Template Code on the Page.ss looks like this:

<% if LifeStyleShot %>	
	<% control LifeStyleShot %>
		<img id="lifestyle" src="$Attachment.URL" width="960" height="401" alt="lifestle" />
	<% end_control %>
<% else %>
	<img id="lifestyle" src="themes/loverschoice/img/lifestyle2.jpg" width="960" height="401" alt="lifestle" />
<% end_if %>

Avatar
Willr

Forum Moderator, 5523 Posts

16 September 2009 at 2:19pm

Try wrapping the template code with <% if ClassName = Security %><% else %><!-- DO CODE --><% end_if %> or you could check for the actual ID. <% if ID %><!-- DO CODE --><% end_if %> or you can put that in your PHP code at the top - if(!$this->ID) return false;

Avatar
zenmonkey

Community Member, 545 Posts

17 September 2009 at 12:07pm

Thanks willr,

The Security Page has an ID of -1 out of curiosity do all the sapphire "utility" pages have negative ID's I can't find them in the Site Tree Table