Jump to:

23486 Posts in 18995 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » DataObject on Page but Not on Security Page

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: 578 Views
  • zenmonkey
    Avatar
    Community Member
    528 Posts

    DataObject on Page but Not on Security Page Link to this post

    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 %>

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: DataObject on Page but Not on Security Page Link to this post

    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;

  • zenmonkey
    Avatar
    Community Member
    528 Posts

    Re: DataObject on Page but Not on Security Page Link to this post

    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

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