[TYPO3-mvc] Get Property of sub object
Mark Kuiphuis
spam at markyourweb.com
Tue Dec 13 10:01:35 CET 2011
Beware: Noob question :D
I am building an extension where I can keep track of members of a dive club.
The members are frontend users and each user will have at least 1 payment record (new
member) or more (if they are renewing their membership)
The members will also have 0, 1 or more certifications as they can join without
having a dive certification, but cannot dive..
I have created the following models:
- Member
- Membership (where the payment information is stored)
- MemberCertification (where the certification information is being stored)
- CertificationAgency (PADI, SSI, NAUI, CMS, BSAC, etc. etc.)
- CertificationLevel (Open Water, Advanced Open Water, etc. etc.) as certification
agencies sometimes use the same name for levels as another certification agency (PADI
Open Water and SSI Open Water) I have made an mm_relation table in between agency and
certification level.
It all works in the backend. I can add multiple payments and multiple certifications
to one member via IRRE.
In my controller I do the following:
$members = $memberRepository->findAll();
This also finds all related certifications and payments (at least that's what's being
outputted via
foreach($members AS $member) {
Tx_ExtDebug::var_dump($member);
}
The debugging info on page shows me all member information as well as multiple
payments and certifications
In the list with all members I would like to show if their membership is still current.
Therefore I need to retrieve the latest payment record (with the most recent date)
If that date is within valid range then the membership is current. Otherwise it is
expired.
In the same list I would also like to show a list with certifications of this member.
As the information is already there (can be seen via Tx_ExtDebug, I thought, after
reading the German book "Zukunftsichere TYPO3-Extensions mit Extbase & Fluid" (page
185 to be precise) I could do someting like this in Fluid:
<h2>Members</h2>
<p>Total members: {totalMembers}</p>
<f:for each="{members}" as="member">
<f:cycle values="{0: 'odd', 1: 'even'}" as="memberClass">
<div class="member member-{memberClass}" id="member-{member.uid}">
<h2>{member.firstName} {member.middleName} {member.lastName}</h2>
<div class="membership-status">Current (needs to be dynamic)
<div class="clear"></div>
</div>
<ul>
<f:for each="{member.certifications}" as="{certification}">
<li>Certification Date: {certification.certDate}</li>
<li>Certification Level: {certification.certLevel}</li>
</f:for>
</ul>
</div>
</f:cycle>
</f:for>
But the output remains empty.....
I read something that I could use {members.certification.certDate} but whatever I
tried I don't see the information I have saved to the database.
I have tried the following:
- {member.certification.certDate}
- {member.certifications.certDate}
- {members.certification.certDate}
- {members.certifications.certDate}
but to no avail...
This will most likely be a matter of "Mark doesn't know enough about this stuff", so
any hints pushing me in the right direction will be appreciated :-)
BTW My MemberController does look like this:
<?php
class Tx_MyExt_Controller_MemberController extends
Tx_Extbase_MVC_Controller_ActionController {
public function listAction() {
$memberRepository =
t3lib_div::makeInstance('Tx_MyExt_Domain_Repository_MemberRepository');
// get members and sort them by lastName;
$members = $memberRepository->findAllMembers();
$totalMembers = $memberRepository->countAll();
foreach($members AS $member) {
Tx_ExtDebug::var_dump($member);
}
$this->view->assign('members', $members);
$this->view->assign('totalMembers', $totalMembers);
}
}
?>
As the certifications and payments are already in the debug info available I was
wondering if I need to do something like this in the listAction function...
public function listAction() {
$memberRepository =
t3lib_div::makeInstance('Tx_MyExt_Domain_Repository_MemberRepository');
$members = $memberRepository->findAllMembers();
$totalMembers = $memberRepository->countAll();
$certifications = $member->getCertifications();
$payments = $member->getPayments();
$this->view->assign('members', $members);
$this->view->assign('totalMembers', $totalMembers);
$this->view->assign('certifications', $certifications);
$this->view->assign('payments', $payments);
}
More information about the TYPO3-project-typo3v4mvc
mailing list