Skip to content
Advertisement

Attempted to call an undefined method named “getEntityManager” of class

I’m learning symfony and I would like to have a search bar to show user with email. But I got and error

JavaScript

If someone can help me or explain me how to do it’s would be very nice. Thanks

In SearchRepository

JavaScript

In SearchController

JavaScript

and search.twig.html

JavaScript

Advertisement

Answer

From the doctrine documentation:

A repository object provides many ways to retrieve entities of the specified type. By default, the repository instance is of type DoctrineORMEntityRepository. You can also use custom repository classes.

So, if your search is going to deal with User objects, you can use the standard UserRepository by doing the following in your Controller:

JavaScript

There is no need for a custom repository for your use case, but if you want to create one and use it for autowiring you must extend ServiceEntityRepository, a container-friendly base repository class provided by Symfony. You can get more details in the documentation. In this case you might want to also review how to annotate your entity to tell the EntityManager that you’ll be using a custom repository.

Sidenote: By default, the action attribute of the form defaults to the same route you are visiting, so if that fragment is part of a layout you’ll have to set it explicitly to your SearchController action: action="{{ path('admin_search') }}"

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement