[TYPO3-dev] Extbase Default Getter of 1:n Relation

g4-lisz at tonarchiv.ch g4-lisz at tonarchiv.ch
Wed Oct 15 12:51:21 CEST 2014


Am 15.10.14 09:09, schrieb Philipp Schiffmann:
> Hi Till,
>
> if fluid encounters {book.introduction} in a template it resolves the
> corresponding method with a simple naming convention: 'get' .
> ucfirst($attribute)
> You can access any method that conforms to this convention, even if your
> model doesn't have an according property. You can do whatever you like in
> these getters, for example:
>
> public function getIntroduction() {
>    foreach ($this->chapters as $chapter) {
>      if ($chapter->getName() == 'introduction') return $chapter;
>    }
>    return NULL;
> }
>
> Note that your getter methods mustn't have parameters, like:
> public function getChapter($chapterName) { /* ... */ }
>
Hi Philipp

Thanks for your answer!

What I meant is a little bit more tricky. Actually it's more a PHP concern:
I want to do PHP class methods "on the fly":
If the class gets a call to an unknown getter, it should redirect it and 
using the name as a parameter.
E.g. getChapterN() should redirect to something like get('ChaptersN').
It's more like higher level programming.
Like this I could use {book.chapterN} for any chapter, without the need 
of extending the class for every new chapter.

Best regards,
Till




More information about the TYPO3-dev mailing list