Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- Classroom.orm.yml
- [code]
- id:
- classID:
- column: class_id
- type: integer
- generator: { strategy: AUTO }
- fields:
- manyToMany: // <---- this is the map
- classUsers:
- targetEntity: acme\UserBundle\Entity\User
- mappedBy: userClassrooms
- oneToMany:
- classAnnouncement:
- targetEntity: acme\ClassroomBundle\Entity\Announcements
- mappedBy: announcementClass
- manyToMany:
- classLesson:
- targetEntity: CloudPod\ClassroomBundle\Entity\Lessons
- inversedBy: lessonClass
- joinTable:
- name: classroom_lessons
- joinColumns:
- fk_class_id:
- referencedColumnName: class_id
- inverseJoinColumns:
- fk_lesson_id:
- referencedColumnName: lesson_id[/code]
- User.orm.yml
- [code]
- acme\UserBundle\Entity\User:
- type: entity
- table: reg_user
- id:
- userID:
- column: user_id
- type: integer
- generator: { strategy: AUTO }
- fields:
- ...
- manyToMany: //this is the map
- userClassrooms:
- targetEntity: acme\ClassroomBundle\Entity\Classroom
- inversedBy: classUsers
- joinTable:
- name: classroom_users
- joinColumns:
- fk_user_id:
- referencedColumnName: user_id
- inverseJoinColumns:
- fk_class_id:
- referencedColumnName: class_id
- [/code]
- Classroom.php
- [code]
- ...
- public function __construct()
- {
- $this->classUsers = new ArrayCollection();
- //other array collections
- $this->classAnnouncement = new ArrayCollection();
- $this->classLesson = new ArrayCollection();
- }
- public function addClassUser(\CloudPod\UserBundle\Entity\User $classUsers)
- {
- $this->classUsers[] = $classUsers;
- return $this;
- }
- public function removeClassUser(\CloudPod\UserBundle\Entity\User $classUsers)
- {
- $this->classUsers->removeElement($classUsers);
- }
- public function getClassUsers()
- {
- return $this->classUsers;
- }[/code]
- Controller
- [code]public function StudentClassroomAction($classID)
- {
- $class_repository = $this->getDoctrine()->getRepository('CloudPodClassroomBundle:Classroom');
- $classroom = $class_repository->find($classID); //im sure this stores an object of classroom
- $userinfo = $classroom->getClassUsers(); //THIS IS THE THING!!!
- //first i tried rendering it in twig. still gives me nothing
- /*return $this->render('CloudPodClassroomBundle:Classrooms:Student.html.twig',array(
- 'classroom' => $classroom,
- 'classuser' => $userinfo));
- */
- //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.
- return new response($userinfo);
- }[/code]
- tbl: classroom_users
- __________________________
- | fk_user_id | fk_class_id |
- ------------------------------------
- | 1 | 1 |
- | 2 | 1 |
- ------------------------------------
- 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