Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Symfony][SF2][Symfony2]Associations
gentleman
post
Post #1





Grupa: Zarejestrowani
Postów: 41
Pomógł: 1
Dołączył: 17.05.2013

Ostrzeżenie: (0%)
-----


Cześć.

Od niedawna bawię się z Symfony2 i mam problem z pobraniem nazwy autora postu. Jakos do tej pory nie mialem problemów (IMG:style_emoticons/default/smile.gif)

Kawałek entity Users:
  1. /**
  2.  * @ORM\Entity
  3.  * @ORM\Table(name="users")
  4.  */
  5. class Users
  6. {
  7. /**
  8.   * @ORM\OneToMany(targetEntity="Comments", mappedBy="users")
  9.   */
  10. protected $comments;
  11.  
  12. public function __construct()
  13. {
  14. $this->comments = new ArrayCollection();
  15. }
  16.  
  17. // ....
Oraz Comments:
  1. /**
  2.  * @ORM\Entity
  3.  * @ORM\Table(name="comments")
  4.  */
  5. class Comments {
  6.  
  7. /**
  8.   * @ORM\ManyToOne(targetEntity="Users", inversedBy="users")
  9.   * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  10.   */
  11.  
  12. protected $users;
  13.  
Wiem że to prymitywny kod ale czytając dokumentacje dowiedziałem się że tak moge pobrać moja nazwe usera. Więc w kontrolerze zrobilem taka funkcje:
  1. public function Username($id) {
  2. $name = $this->getDoctrine()
  3. ->getRepository('AcmeForumBundle:Comments')
  4. ->find($id);
  5.  
  6. $username = $name->getUsers()->getName();
  7.  
  8. return $username;
  9. }

ale nic sie nie dzieje.W czym polega błąd?

Ten post edytował gentleman 6.07.2013, 11:56:17
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 26.12.2025 - 10:30