I am new to Symfony2 and using fosuserbundle. I have created a small project using fosuserbundle which has a registration, login, 2 forms consisting of radio buttons to choose
It's because you are creating a new Subscriptions
entity every time in the controller:
$subscriptions = new Subscriptions();
And you don't even use it in the createForm
:
$form = $this->createForm(new SubscriptionsType, new Subscriptions());
Plus there's no point where the Subscription
is associated with your user, who I'm assuming is a Student
entity. To fix this, you must do something like:
if (!($subscriptions = $this->getUser()->getSubscriptions())) { // This line may not be right
$subscriptions = new Subscriptions();
$subscriptions->setStudents($this->getUser());
}
$form = $this->createForm(new SubscriptionsType, $subscriptions);
I suspect that there are other "holes" in your development, so this won't be a complete solution to your issues, but it addresses the main point to your question.
The line that may not be right could also be something like:
if (!($subscriptions = $em->getRepository('InstituteEventsStudentBundle:Subscriptions')->findBy(...))) {