I have a delete link to delete a Comment object by ID /comment/:id/delete
In order to secure this link I add a csrf token to the link
$CSRFTokenForm = new BaseForm();
$link = url_for(..., array('_csrf_token' => $CSRFTokenForm->getCSRFToken()));
and in the executeDelete i use the checkCSRFProtection()
method, and it all works fine.
The only thing is that each comment is displayed by a partial, and each partial creates it's own BaseForm()
in order to create the token, which is waste of time since they're all the same..
Do you have a better idea on how to make it more efficient, like maybe a static getCSRFToken()
method or creating a global BaseForm()
?