Hi everyone,
I am having problems looping through a members list (DataObjectSet) and would like to ask for a small amount of your time to advise me please.
Example code of problem:
OurSupporters.php
function pullMembers(){
$members = DataObject::get('Member');
foreach($members as $member){
return $member;
}
}
An example of the output file:
OurSupporters.ss
<h1>$Title</h1>
<table>
<th>
<td>First Name</td>
<td>Surname</td>
</th>
<% control pullMembers %>
<tr>
<td>$FirstName</td>
<td>$Surname</td>
</tr>
<% end_control %>
</table>
When running it will only display the first member - though it may be a problem with the array so I did try intoArray() but didn't work.
Though if I remove the foreach statement and "return $members;" it lists all the members but unfortunately it does not help my problem as I need to add each member into a new member class to use inGroup() on a ifelse statement.
This causes a problem when I wish to find group of a member, like so:
OurSupporters.php
function pullMembers(){
$members = DataObject::get('Member');
foreach($members as $member){
$privateMember = new Member();
$privateMember = $member;
if($privateMember->inGroup(5)){
return $member;
}else{
//Do nothing
}
}
}
Thanks for your help in advance. I am new to silverstripe and convinced I am overlooking something here...