Explain $getWorkerInformationByMember
August 18, 2025 · AI Conversations
Hallo $Name
Zur Übersicht
Selbstauskunft hinzufügen
$FormError
$FormSuccess
$FirstName $LastName
Mietinteressent:in
$FirstName $LastName
Standaard contact
$PositionUnterneehmen
E-mail: $Email
Zusätizlche E-mail: $ZusaEmail
Tel: $CountryCode $Telefon
Mobiel: $Mobile
Fax: $Fax
$Description
um zu sehen
hinzufügen
<script>
const accordions = document.querySelectorAll('.accordion');
accordions.forEach(acc => {
acc.querySelector('.accordion-header').addEventListener('click', () => {
// Optional: Close others before opening
accordions.forEach(item => {
if (item !== acc) item.classList.remove('active');
});
acc.classList.toggle('active');
});
});
</script>
### What the method returns
public function getWorkerInformationByMember(){
$member = Security::getCurrentUser();
$memberID = $member->ID;
return RentalWorkerInformation::get()
->filter('MemberID', $memberID)
->sort('ID', 'ASC');
}
– **Fetch current user**: `Security::getCurrentUser()` gets the logged-in `Member`.
– **Filter records**: Queries the `RentalWorkerInformation` DataObject table for rows where `MemberID` equals the current user’s ID.
– **Return a DataList**: Returns a **lazy** `DataList` (not executed until you loop over it).
– **Sort order**: `ID ASC` → oldest first.
### How the template uses it
<% loop $getWorkerInformationByMember %>
...
<% if $Image %>
<img src="$Image.URL" alt="$FirstName $LastName">
<% else %>
<img src="/themes/template/images/user_thumb.png" alt="User Thumb">
<% end_if %>
<h3>$FirstName $LastName</h3>
...
<% end_loop %>
– In SilverStripe templates, writing `$getWorkerInformationByMember` calls the controller method `getWorkerInformationByMember()` and gets the `DataList`.
– “ iterates each `RentalWorkerInformation` record.
– Inside the loop, `$FirstName`, `$LastName`, `$Email`, etc. are fields on each **RentalWorkerInformation** record.
– `$Image.URL` works if the DataObject has a `has_one Image` relation (i.e., an `ImageID` column). If there’s no image, your template shows a default avatar.
### Edge cases / notes
– If the member isn’t logged in, your `init()` already redirects to `/public/login`, so this method won’t run for guests.
– If there are no worker records, the loop renders nothing (no error).
### Common tweaks
– **Newest first**:
->sort('Created', 'DESC')
– **Limit results**:
->limit(10)
– **Filter only “standard contact” workers** (if that’s a DB field):
->filter(['StandaardContact' => 1])
That’s it—the method is just a clean, template-callable query for “all my workers,” and the loop renders each worker’s details.