TYPO3 Extbase bidirectional 1:n relation

杀马特。学长 韩版系。学妹 提交于 2019-12-23 05:17:59

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!