Sonata mongodb admin捆绑过滤器参考

时间:2016-06-10 11:48:48

标签: mongodb sonata-admin symfony sonata

我有

的文件

/** @MongoDB\ReferenceMany(targetDocument="NewsTag") */ private $tags;

关系。

在我的奏鸣曲管理员中,我想按标签过滤列表。我尝试使用

$datagridMapper->add('tags', null, array(), null, array('expanded' => true, 'multiple' => true))

与文档一样,但有错误

Could not load type "document"

有人知道为什么吗?

UPD:堆栈跟踪

Symfony\Component\Form\Exception\InvalidArgumentException: Could not load type "document"
at n/a
    in /var/www/meteoprog-site-s3/vendor/symfony/symfony/src/Symfony/Component/Form/FormRegistry.php line 87

at Symfony\Component\Form\FormRegistry->getType('document')
    in /var/www/meteoprog-site-s3/vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php line 83

at Symfony\Component\Form\FormFactory->createNamedBuilder('value', 'document', null, array('required' => false, 'class' => 'AppBundle\Document\NewsTag', 'expanded' => true, 'multiple' => true))
    in /var/www/meteoprog-site-s3/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php line 106

at Symfony\Component\Form\FormBuilder->create('value', 'document', array('required' => false, 'class' => 'AppBundle\Document\NewsTag', 'expanded' => true, 'multiple' => true))
    in /var/www/meteoprog-site-s3/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php line 267

at Symfony\Component\Form\FormBuilder->resolveChildren()
    in /var/www/meteoprog-site-s3/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php line 215

at Symfony\Component\Form\FormBuilder->getForm()
    in /var/www/meteoprog-site-s3/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php line 221

at Symfony\Component\Form\FormBuilder->getForm()
    in /var/www/meteoprog-site-s3/var/cache/dev/classes.php line 11085

at Sonata\AdminBundle\Datagrid\Datagrid->buildPager()
    in /var/www/meteoprog-site-s3/var/cache/dev/classes.php line 11189

at Sonata\AdminBundle\Datagrid\Datagrid->getForm()
    in /var/www/meteoprog-site-s3/vendor/sonata-project/admin-bundle/Controller/CRUDController.php line 105

at Sonata\AdminBundle\Controller\CRUDController->listAction()
    in  line 

at call_user_func_array(array(object(LanguagesAdminController), 'listAction'), array())
    in /var/www/meteoprog-site-s3/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 139

at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
    in /var/www/meteoprog-site-s3/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 62

at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
    in /var/www/meteoprog-site-s3/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php line 169

at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
    in /var/www/meteoprog-site-s3/web/app_dev.php line 30

1 个答案:

答案 0 :(得分:2)

因此,如果您想使用sonata_type_model进行过滤,可能会出现一个错误。您在ChoiceField中没有modelManager。 但您可以在configureDatagridFilters中手动添加它,如下所示:

   $datagridMapper
        ->add('tags', null, [], 'sonata_type_model',
            [
                'model_manager' => $datagridMapper->getAdmin()->getModelManager(), 
                'property' => 'name', 
                'multiple' => true, 
                'by_reference' => false
            ]);