How to display the user's already selected radio buttons after logging in symfony2

后端 未结 1 1474
旧时难觅i
旧时难觅i 2021-02-11 09:06

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

1条回答
  •  隐瞒了意图╮
    2021-02-11 09:44

    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(...))) {
    

    0 讨论(0)
提交回复
热议问题