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, simon_w

Help with $mySet->find('Status', 'special');


Reply


4 Posts   799 Views

Avatar
eceers

Community Member, 24 Posts

2 September 2009 at 6:26pm

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 [url]http://doc.silverstripe.com/doku.php?id=dataobjectset[/url] 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.

Avatar
Willr

Forum Moderator, 5513 Posts

2 September 2009 at 7:02pm

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();

Avatar
eceers

Community Member, 24 Posts

2 September 2009 at 7:25pm

Thanks Willr worked a treat.

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

Avatar
Willr

Forum Moderator, 5513 Posts

2 September 2009 at 7:46pm

Nope Sorry. NZ based.