Skip to content

Instantly share code, notes, and snippets.

@bernard-ng
Created December 23, 2020 13:55
Show Gist options
  • Save bernard-ng/19a2d780b658c6478ac9c119854ddcb4 to your computer and use it in GitHub Desktop.
Save bernard-ng/19a2d780b658c6478ac9c119854ddcb4 to your computer and use it in GitHub Desktop.
<?php
// ...
use App\Entity\Task;
use Symfony\Component\OptionsResolver\OptionsResolver;
class TaskType extends AbstractType
{
// ...
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Task::class,
// activer/désactiver la protection du CSRF pour ce formulaire
'csrf_protection' => true,
// le nom du champ HTML caché qui stocke le jeton
'csrf_field_name' => '_token',
// une chaîne arbitraire utilisée pour générer la valeur du jeton
// l'utilisation d'une chaîne de caractères différente pour chaque formulaire améliore sa sécurité
'csrf_token_id' => 'task_item',
]);
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment