I have 3 entities : User , UserRole , UserProfile.
My primary key for the userprofile entity is actually a foreign key from user entity which is the UserId.
Everytime I try to access userProfile using the foreign key userid. I always got an error of undefined index of userID.
this is the exact error message
Notice: Undefined index: userID in C:\wamp\www\SymfonyFolder\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php line 2583
Controller
- Code: Select all
.....
....
public function profileAction($id)
{
$user = new User();
$user_repository = $this->getDoctrine()->getRepository('AcmePodUserBundle:User');
$user = $user_repository->find($id);
$userprofile = new UserProfile();
$userprofile_repository = $this->getDoctrine()->getRepository('AcmeUserBundle:UserProfile');
$userprofile = $userprofile_repository->find($user);
return new Response($userprofile); // this is not the actual output i need. I just used this simply to test if userprofile has some value.
}
User.orm.yml
- Code: Select all
type: entity
table: reg_user
oneToOne:
id:
userID:
column: user_id
type: integer
generator: { strategy: AUTO }
targetEntity: UserProfile
mappedBy: userProfileID
UserProfile.orm.yml
- Code: Select all
type: entity
table: users_profile
id:
userProfileID:
associationKey: true
fields:
firstName:
column: first_name
type: string
length: 255
unique: true
nullable: false
lastName:
column: last_name
type: string
length: 255
nullable: false
oneToOne:
userProfileID:
targetEntity: User
inversedBy: userID
joinColumn:
name: fk_user_id
referencedColumnName: user_id
I think the problem is on my controller codes. Can somebody tell me the proper way of coding it.
P.S I seperated the user to user profile because i dont want to mix up in a table the user account data(like username, role, etc.) with its user info.
