1
votes

I have a classical course and dates relation (one course has many dates). The next courses shall be listed on a page. I loaded all dates with the normal findAll() method with sorting by startDate. Now i need the parent course information in order to show course details.

In the date controller i have

/**
 * Course
 *
 * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\ITServicePN\ItspnKurse\Domain\Model\Kurse>
 */
protected $kurse = NULL;

/**
 * Returns the Courses
 * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\ITServicePN\ItspnKurse\Domain\Model\Kurse> $kurse
 */
public function getKurse() {
    return $this->kurse;
}

This returns me the course when using f:debug {date.kurse}:

TYPO3\CMS\Extbase\Persistence\ObjectStorageprototypeobject (1 items) ... => ITServicePN\ItspnKurse\Domain\Model\Kurseprototypepersistent entity (uid=8, pid=51)
      title => 'The name of the course' ...

But when i try to access {date.kurse.title} i got a TYPO3 exception:

#1: PHP Warning: spl_object_hash() expects parameter 1 to be object, string given in /var/www/vhosts/it-service-pn.de/cetba/typo3_src-6.2.3/typo3/sysext/extbase/Classes/Persistence/ObjectStorage.php line 174

What to do, to get the parents object information properly with extbase and fluid?

1

1 Answers

2
votes

According to your Model, kurse is an ObjectStorage. That means when accessing date.kursein fluid you will get an Array back. You can iterate over that array in fluid with the for-Viewhelper

<f:for each="{date.kurse}" as="kurs">
    Kurs: {kurs.title}
</f:for>

You can also print the index of the iteration to get a numbered list of kurses.

<f:for each="{date.kurse}" as="kurs" iteration="i">
    {i.cycle}. Kurs: {kurs.title}
</f:for>