Php symfony2提交所选请求字段

Php symfony2提交所选请求字段,php,forms,symfony,symfony-forms,Php,Forms,Symfony,Symfony Forms,在某些情况下,我只想将整个表单的两个字段更新到数据库中,即使用户更改了所有其他字段 $form = $this->createForm('user', $user); $form->submit($request); if($certain_conditions){ // update only the "favourites collection" and don't entertain other user changes.? } $em->flush(); 有什么可行

在某些情况下,我只想将整个表单的两个字段更新到数据库中,即使用户更改了所有其他字段

$form = $this->createForm('user', $user);
$form->submit($request);
if($certain_conditions){
 // update only the "favourites collection" and don't entertain other user changes.?
}
$em->flush();

有什么可行的方法吗?

没关系,我找到了解决办法

$form = $this->createForm('user', $user); if($certain_conditions){ foreach($form as $k=>$v){ if($k != 'favourites') $form->remove($k); } } $form->submit($request); $em->flush(); $form=$this->createForm('user',$user); 如果($某些条件){ foreach($k=>v形式){ 如果($k!=“收藏夹”)$form->remove($k); } } $form->submit($request); $em->flush();