Advertisement
Guest User

Untitled

a guest
Dec 28th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. Everytime I try to get all the users inside a specific classroom using its id, it returns me nothing. I have a jointable with user_id and class_id
  2.  
  3. Classroom.orm.yml
  4. [code]
  5. id:
  6. classID:
  7. column: class_id
  8. type: integer
  9. generator: { strategy: AUTO }
  10. fields:
  11. manyToMany: // <---- this is the map
  12. classUsers:
  13. targetEntity: acme\UserBundle\Entity\User
  14. mappedBy: userClassrooms
  15. oneToMany:
  16. classAnnouncement:
  17. targetEntity: acme\ClassroomBundle\Entity\Announcements
  18. mappedBy: announcementClass
  19. manyToMany:
  20. classLesson:
  21. targetEntity: CloudPod\ClassroomBundle\Entity\Lessons
  22. inversedBy: lessonClass
  23. joinTable:
  24. name: classroom_lessons
  25. joinColumns:
  26. fk_class_id:
  27. referencedColumnName: class_id
  28. inverseJoinColumns:
  29. fk_lesson_id:
  30. referencedColumnName: lesson_id[/code]
  31.  
  32. User.orm.yml
  33.  
  34. [code]
  35. acme\UserBundle\Entity\User:
  36. type: entity
  37. table: reg_user
  38. id:
  39. userID:
  40. column: user_id
  41. type: integer
  42. generator: { strategy: AUTO }
  43. fields:
  44. ...
  45. manyToMany: //this is the map
  46. userClassrooms:
  47. targetEntity: acme\ClassroomBundle\Entity\Classroom
  48. inversedBy: classUsers
  49. joinTable:
  50. name: classroom_users
  51. joinColumns:
  52. fk_user_id:
  53. referencedColumnName: user_id
  54. inverseJoinColumns:
  55. fk_class_id:
  56. referencedColumnName: class_id
  57. [/code]
  58.  
  59. Classroom.php
  60. [code]
  61. ...
  62. public function __construct()
  63. {
  64. $this->classUsers = new ArrayCollection();
  65. //other array collections
  66. $this->classAnnouncement = new ArrayCollection();
  67. $this->classLesson = new ArrayCollection();
  68. }
  69. public function addClassUser(\CloudPod\UserBundle\Entity\User $classUsers)
  70. {
  71. $this->classUsers[] = $classUsers;
  72. return $this;
  73. }
  74.  
  75. public function removeClassUser(\CloudPod\UserBundle\Entity\User $classUsers)
  76. {
  77. $this->classUsers->removeElement($classUsers);
  78. }
  79. public function getClassUsers()
  80. {
  81. return $this->classUsers;
  82. }[/code]
  83.  
  84. Controller
  85. [code]public function StudentClassroomAction($classID)
  86. {
  87.  
  88. $class_repository = $this->getDoctrine()->getRepository('CloudPodClassroomBundle:Classroom');
  89. $classroom = $class_repository->find($classID); //im sure this stores an object of classroom
  90. $userinfo = $classroom->getClassUsers(); //THIS IS THE THING!!!
  91. //first i tried rendering it in twig. still gives me nothing
  92. /*return $this->render('CloudPodClassroomBundle:Classrooms:Student.html.twig',array(
  93. 'classroom' => $classroom,
  94. 'classuser' => $userinfo));
  95. */
  96. //I change it to response to know if something is stored in $userinfo it returns an empty page rather than an error.Then $userinfo still has no object stored.
  97. return new response($userinfo);
  98.  
  99.  
  100. }[/code]
  101.  
  102. tbl: classroom_users
  103. __________________________
  104. | fk_user_id | fk_class_id |
  105. ------------------------------------
  106. | 1 | 1 |
  107. | 2 | 1 |
  108. ------------------------------------
  109.  
  110. Can anybody tell me, whats wrong? I really cant pinpoint which is which specially now since it doesn't return any error to me.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement