Symfony2支持为框架启用或禁用csrf_protection,例如:
csrf_protection:
enabled: false
或
csrf_protection:false
我们应该注意到两个配置完全不同,第一个意味着加载了csrf但是为false,我们甚至没有加载这个功能的senconde。好吧,我们可以轻松地为特殊形式启用它,例如:
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'xxx\Entity\Company',
'csrf_protection' => true,
);
}
在表单构建器类中。
但我认为这还不够,所以我问这个问题,我们可以这样做:
mybundle:
csrf_protection:
enabled: false
答案 0 :(得分:1)
您可以在config.yml
文件中为项目中的每个捆绑包全局禁用csrf_protection,但我认为不可能只对其中一个捆绑包执行此操作。
相反,您需要修改该bundle的每个Form类的options数组,如下所示:
class TaskType extends AbstractType
{
// ...
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'Acme\TaskBundle\Entity\Task',
'csrf_protection' => false
);
}
// ...
}