1
ID를 사용하여 특정 교실에있는 모든 사용자를 얻으려고 할 때마다, 아무 것도 반환하지 않습니다. 나는 user_id 및 class_id와 결합 할 수 있습니다.Symfony2 Array Collection은 아무 것도 반환하지 않습니다.
Classroom.orm.yml
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: acme\ClassroomBundle\Entity\Lessons
inversedBy: lessonClass
joinTable:
name: classroom_lessons
joinColumns:
fk_class_id:
referencedColumnName: class_id
inverseJoinColumns:
fk_lesson_id:
referencedColumnName: lesson_id
User.orm.yml
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
Classroom.php
...
public function __construct()
{
$this->classUsers = new ArrayCollection();
//other array collections
$this->classAnnouncement = new ArrayCollection();
$this->classLesson = new ArrayCollection();
}
public function addClassUser(\acme\UserBundle\Entity\User $classUsers)
{
$this->classUsers[] = $classUsers;
return $this;
}
public function removeClassUser(\acme\UserBundle\Entity\User $classUsers)
{
$this->classUsers->removeElement($classUsers);
}
public function getClassUsers()
{
return $this->classUsers;
}
Controller
public function StudentClassroomAction($classID)
{
$class_repository = $this->getDoctrine()->getRepository('acmeClassroomBundle: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('acmeClassroomBundle: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);
}
tbl: classroom_users
______________________________
| fk_user_id | fk_class_id|
-------------------------------
| 1 | 1 |
| 2 | 1 |
-------------------------------
아무도 말해 줄 수 있습니까? 나는 그것이 정말로 나에게 어떠한 오류도 돌려주지 않았기 때문에 특별히 어느 것이 정확한지 정확히 알 수 없다.
에 classroom.orm.yml를 수정? 'php app/console do : sch : va' 당신은 얻을 수 있어야합니다 '매핑 [OK] - 매핑 파일이 올바른지 확인하십시오. [Database] OK - 데이터베이스 스키마가 매핑 파일과 동기화되었습니다. ' – l3l0
감사합니다. 지도를 확인하는 명령이 있다는 것을 몰랐습니다. – Teffi