I have an entity form with Symfony :

我有一个Symfony的实体表格:

class MyType extends AbstractType
{

    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
       ...
    }

    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'LogicielBundle\Entity\FichierGroup',
            'intention' => $this->getName() . '_token'
        ));
    }

But in POST_SUBMIT event, I want to return null (no entity). I tested this but not working :

但是在POST_SUBMIT事件中,我想返回null(没有实体)。我测试了这个,但没有工作:

    $builder->addEventListener(FormEvents::POST_SUBMIT, function(FormEvent $event) {
        .... my condition ...
        $event->setData(null);
    });

Can you help me ? Thanks :)

你可以帮我吗 ?谢谢 :)

3 个解决方案

#1


1

Could you please post you controller code? Do you pass an object reference to createForm, or do you use $form->getData() ? In your case, you should stick to the second.

你能告诉你控制器代码吗?您是否将对象引用传递给createForm,还是使用$ form-> getData()?在你的情况下,你应该坚持第二个。

Try using SUBMIT event instead of POST_SUBMIT. As Symfony doc states it, "It can be used to change data from the normalized representation of the data.".

尝试使用SUBMIT事件而不是POST_SUBMIT。正如Symfony doc所述,“它可用于从数据的规范化表示中更改数据。”

更多相关文章

  1. 使用/发送POST数据时的libcurl C问题(不是c++)
  2. PHP:在类中使用数据库
  3. 纯真ip数据库查询的php实现(补充分组查询)
  4. 添加到数据库后,保持在同一页面而不刷新它
  5. PHP 导出 万级别数据 时间测试
  6. 数据库是存储我的Web应用程序数据的最佳选择吗?
  7. 使用没有实体类的本机SQL查询
  8. php执行数据库查询返回json格式数据
  9. PHP更新基于其他表的表数据

随机推荐

  1. 用ndk环境编译android可用的so库
  2. 谁说Android的动画不廉价(一)之项目分层
  3. android 中Xml里面的id重名问题
  4. 【Android】Android江湖
  5. 【Android实战之旅 001】AsyncTask异步操
  6. Android中Drawable适配介绍
  7. 隐藏Listview和RecyclerView 滑动边界的
  8. Android中使用Handler和异步任务(AsyncTac
  9. 【Android应用开发】分享一个录制 Androi
  10. 从我的android说起