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


4 Posts   752 Views


2 September 2009 at 6:26pm Community Member, 24 Posts

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 %>
   <% 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][/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.


2 September 2009 at 7:02pm Forum Moderator, 5511 Posts

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") {

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


2 September 2009 at 7:25pm Community Member, 24 Posts

Thanks Willr worked a treat.

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


2 September 2009 at 7:46pm Forum Moderator, 5511 Posts

Nope Sorry. NZ based.