问题
Let's say we have a 1:n relation between an Author
and Book
model. Modeling the relation using the Extension Builder, the necessary code to get Book
's for an author is provided.
But what about the inverse? How do I get the Author
for a given Book
class?
回答1:
I assume you have created the following domain model with the Extension Builder.
When you create a 1:n relation between Author and Book, the resulting database table for Book will contain a field which holds the UID of the author. To make use of this field, you have to add a getter in your book domain model to return the corresponding author for the given book.
Add the following to your domain model for book:
/**
* Returns the author
*
* @var \TYPO3\YourExtension\Domain\Model\Author
*/
protected $author;
/**
* @return \TYPO3\YourExtension\Domain\Model\Author
*/
public function getAuthor() {
return $this->author;
}
Now you can use the new getter in Fluid to return the author of a given book with {book.author}
回答2:
You can add n:1 relation to Book model, then Extension builder will create getter and setter automatically..
来源:https://stackoverflow.com/questions/21017525/typo3-extbase-bidirectional-1n-relation