문제

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?

도움이 되었습니까?

해결책

I assume you have created the following domain model with the Extension Builder.

Domain model built with 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}

다른 팁

You can add n:1 relation to Book model, then Extension builder will create getter and setter automatically..

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top