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

DataObject on Page but Not on Security Page


Go to End
Reply


3 Posts   715 Views

Avatar
zenmonkey

Community Member, 541 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, 5521 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, 541 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