[TYPO3-mvc] Get data from a relateted model

Franz Koch typo3.RemoveForMessage at elements-net.de
Mon Jan 11 12:30:33 CET 2010


Hi,

> i have a problem with a 1:n (Author has many Books) Relation. I have a field
> 'author' in the Book-Table witch contains the uid of the author. In the
> model of the Book i create the getter for author but in the view i get only
> the uid. How can i get the complete data of the author? Does someone have an
> example or a link?

It's all about proper annotations in your model. If you have them, 
extbase knows everything to provide the proper objects for you. So your 
class should look like this.

class Tx_YourExt_Domain_Model_Book extends .... {

   /**
    * The author of the book
    * @var Tx_YourExt_Domain_Model_Author
    */
    protected $author;


    /**
     * Setter for the author
     *
     * @param Tx_YourExt_Domain_Model_Author $author The author of the book
     * @return void
    function setAuthor(Tx_YourExt_Domain_Model_Author $author) {
      $this->author = $author;
    }


    /**
     * Getter for author of the book
     *
     * @return Tx_YourExt_Domain_Model_Author author
     */
    public function getAuthor() {
      return $this->author;
    }
}

-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list