Persistence · Question 6 of 12

Which type do you use in an Extbase model for a property that holds several related objects, e.g. all speakers of a conference?

1 answer is correct. Easy

Show answer

Answer

  • A \TYPO3\CMS\Extbase\Persistence\ObjectStorage

Explanation

For 1:n and m:n relations Extbase uses the class ObjectStorage, e.g. protected ObjectStorage $speakers; with the annotation @var ObjectStorage<Speaker> for the IDE and static analysis. Entries are added through methods such as addSpeaker(), which call attach() internally, and removed with detach(). In the template you iterate the relation with <f:for each="{conference.speakers}" as="speaker">. The ObjectStorage must be initialised before it is accessed, otherwise an error occurs. PHP's SplObjectStorage looks similar, but Extbase cannot load relations into it or persist changes to it.

Certifications & exams

Which exam comes next?

You can already practise for 19 exams, and 21 are up for a vote. See all certifications with their official information, cast your vote or suggest your exam.

See all certifications