Skip to content
Advertisement

Entity not found with Symfony 5.1

I have an issue with an Entity. The goal is to display a Form which the user can use to change his personal information like the Email or password. I created a form for that, but when I created the /Edit Route I get the following error:

“AppEntityUsers object not found by the @ParamConverter annotation.”

Here’s my Controller:

JavaScript

Here’s the form:

JavaScript

Here’s the Entity Users:

JavaScript

Here’s the View Editprofile.html.twig:

JavaScript

Advertisement

Answer

order matters. especially when routing without requirements. you have the following routes (update: added prefix, thanks @Cerad!):

JavaScript

now, when you request the uri /users/edit the UrlMatcher will iterate over your routes to see if and which matches, stopping on the first match.

/users/ obviously doesn’t match /users/{id} does match, since {id} is allowed to be any alpha-numeric string (+ few extra chars), and edit matches that, leading to the users_show route, on which the User object cannot be determined by the id “edit`. And thus, the error message appears. One way to fix this would be to add requirements to the route matching – assuming the id is numerical only:

JavaScript

I also agree with @Cerad that Users is a very bad name for an entity. They’re usually in singular form.

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