Jump to:

3462 Posts in 1065 Topics by 740 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Pointing to the dataobject being displayed

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

Page: 1
Go to End
Author Topic: 837 Views
  • mattconfusion
    Avatar
    Community Member
    48 Posts

    Pointing to the dataobject being displayed Link to this post

    i have some dataobjects linked to page type. i display these objects in the template, performing a simple control nameoftheobjects, and displaying them.
    and this works. while displaying them, i need to perform a control on them, like "if a certain dataobject field is equal to some value, return true."
    I plan to do this creating a function in the page controller. but how i can point to the current dataobject being displayed?

    <% control nameoftheobjects %>
    <% if checkontheobjects %>
       do somtehing with it
       <% else %>
       do something else with it
    <% end_if %>
    <% end_control %>

  • mark_s
    Avatar
    Community Member
    78 Posts

    Re: Pointing to the dataobject being displayed Link to this post

    Hi.

    In your example, <% control nameoftheobjects %> will iterate over the set of data objects. Within the <% control %> ... < % end_control %> structure, a reference to $foo is a reference to the foo propery or method on the current object. That is, inside the control loop, the default context changes to the data object being iterated, rather than the page. If `checkontheobjects` is a property or method of the data object, it is evaluated against the current data object being iterated, so that is probably exactly what you want.

    Mark

  • mattconfusion
    Avatar
    Community Member
    48 Posts

    Re: Pointing to the dataobject being displayed Link to this post

    yeah, you're right, thanks! Calling a method created inside the php describing this dataobject allows you to have an "implicit" pointing to the object itself. Very useful thing: it's OO programming mindset after all. Thanks, now it works.

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