简体   繁体   中英

Sonata ModelAutocompleteType Query/Callback

I'd like to use something like a query_builder for the EntityType::class so I can only display specific results.

I noticed according to the docs you can use callback but I was struggling to figure out how I'd apply this.

My working EntityType example:

'query_builder' => function (MyRepository $repository) use ($example) {
    return $repository->findByExampleBuilder($example);
}

This returns a query builder which works. How can I apply something similar to the ModelAutocompleteType callback?

This documentation section might help you https://symfony.com/doc/master/bundles/SonataAdminBundle/reference/form_types.html use SonataAdminBundleFormTypeModelAutocompleteType. As your question is hard to understand due to lack of context, you might also be interested in https://sonata-project.org/bundles/doctrine-orm-admin/master/doc/reference/filter_field_definition.html doctrine_orm_model_autocomplete.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM