Jump to:

23355 Posts in 17702 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Help with $mySet->find('Status', 'special');

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: 727 Views
  • eceers
    Avatar
    Community Member
    24 Posts

    Help with $mySet->find('Status', 'special'); Link to this post

    I've got dataObject with a column called attributes and with that there are three options that it can hold (Event, Membership, Course). When I get to a summary page I' wishing to show these in different control blocks. In which I'm using a function like this in the controller;

       
    function getEvents() {
          $events = getCart()->find('attrib', 'event');
    return $events ;
    }

    and in my template i'm using;

    <% if getEvents %>
       <% control getEvents %>
          <h2>$title</h2>
          <p>$date</p>
       <% end_control %>
    <% end_if %>

    Now the problem is I'm having is the getEvents function only returns me one object, where I know there is more than one.

    This page http://doc.silverstripe.com/doku.php?id=dataobjectset mentions that it returns Multiple elements.

    I'm sorry if this is a basic question I'm new to Silverstripe and php class's so its all a bit above me at the moment.

    Thanks in advance.

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: Help with $mySet->find('Status', 'special'); Link to this post

    Actually that page lies. find() returns the first object which matches the value. Bit odd that there is not a method which gets the whole subset. You might have to do your own check.

    $events = getCart();
    if($events) {
    foreach($events as $event) {
    if($event->attrib != "event") {
    $events->remove($event);
    }
    }
    }

    Or using a DataObject::get("Whatever", "attrib = 'event'") to get the events rather then getCart();

  • eceers
    Avatar
    Community Member
    24 Posts

    Re: Help with $mySet->find('Status', 'special'); Link to this post

    Thanks Willr worked a treat.

    You wouldn't happen to live in South Aus would you?

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: Help with $mySet->find('Status', 'special'); Link to this post

    Nope Sorry. NZ based.

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