21293 Posts in 5733 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 648 Views |
-
Help with $mySet->find('Status', 'special');

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 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.
-
Re: Help with $mySet->find('Status', 'special');

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();
-
Re: Help with $mySet->find('Status', 'special');

2 September 2009 at 7:25pm
Thanks Willr worked a treat.
You wouldn't happen to live in South Aus would you?
| 648 Views | ||
|
Page:
1
|
Go to Top |


