Forms 如何在formtype symfony2中添加where子句

Forms 如何在formtype symfony2中添加where子句,forms,symfony,include,Forms,Symfony,Include,我一直在寻找这个问题的解决方法。我刚刚学会了symfony2,但我找不到一个方法,我尝试了在网上找到的不同的东西,但我没有找到任何工作 这是我的问题,我有一个表单PictureType,其中包括另一个实体集合(这是一个图片集合,或者如果您更喜欢图片集) 当用户上传他的照片时,他需要选择他想把它放在哪个相册中 我的问题是,我不知道如何在我的PictureType中只选择当前用户的集合 这是我的图片类型 $builder ->add('file') ->

我一直在寻找这个问题的解决方法。我刚刚学会了symfony2,但我找不到一个方法,我尝试了在网上找到的不同的东西,但我没有找到任何工作

这是我的问题,我有一个表单PictureType,其中包括另一个实体集合(这是一个图片集合,或者如果您更喜欢图片集)

当用户上传他的照片时,他需要选择他想把它放在哪个相册中

我的问题是,我不知道如何在我的PictureType中只选择当前用户的集合

这是我的图片类型

 $builder
        ->add('file')
        ->add('collection', 'entity', array(
            'class' => 'AppPictureBundle:Collection',
            'property' => 'name'
            ));
我想在属性后面插入这样的内容

其中'user_id'=$this->getUser()

我有一个manyToOne on Collection target User和一个manyToOne on picture target Collection。

这是因为:

$builder
    ->add('file')
    ->add('collection', 'entity', array(
        'class' => 'AppPictureBundle:Collection',
        'property' => 'name',
        'query_builder' => function (EntityRepository $er) {
            return $er->createQueryBuilder('c')
                ->where('c.user = :user')
                ->setParameter('user', $this->getCurrentUser());
        },
    ));

嗨,Elnur,我试过这个$user=$container->get('security.context')->getToken()->getUser();->setParameter('user',$user);但是我有一个错误500,我需要重新启动wamp才能加载任何页面!!