Disable symfony 2 csrf token protection on ajax submit

后端 未结 5 417
遇见更好的自我
遇见更好的自我 2020-12-08 13:07

i\'m building a mobile app talking to my symfony2 app via webservices I can\'t find a way to disable csrf protection on a specific controller/action

i want to post r

5条回答
  •  一整个雨季
    2020-12-08 13:26

    Using the form factory in Symfony 3

    use Symfony\Component\Form\Extension\Core\Type\FormType;
    
    $form = $this->container->get('form.factory')
        ->createNamedBuilder(null, FormType::class, null, array('csrf_protection' => false))
        ->add('yourField','text', array(
            'label' => false,
            'mapped' => false
        ))
        ->getForm();
    

    Adapted from Mick's answer

提交回复
热议问题