Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
194 views
in Technique[技术] by (71.8m points)

php - AppEntityPlaylistForCompany object not found by the @ParamConverter annotation

For several days now I have been stuck on this error: error : AppEntityPlaylistForCompany object not found by the @ParamConverter annotation.

Here is the code for the controller (admin_company_parcours):

controller : admin_company_parcours

If you have any ideas on what this might look like knowing that I've tried a few tricks already without success. Thanking you, cordially

question from:https://stackoverflow.com/questions/65872201/app-entity-playlistforcompany-object-not-found-by-the-paramconverter-annotation

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Symfony succesfully resolves your Company entity using the id parameter in your route. However, Symfony can't automatically resolve more than one entity unless your route contains more parameters. Therefore, $playlistForCompany can't be resolved as Symfony does not know which entity to query.

As you are not persisting any new value in your code, I assume that $playlistForCompany must be an existing entity, somewhat related to $company.

  1. If your Company entity has an association field to the PlaylistForCompany entity, you can retrieve it using the corresponding getter.
  2. If not, you will have to use your PlaylistRepository and manually retrieve it.
public function parcours(Company $company, Request $request): Response
{
  $entityManager = $this->getDoctrine()->getManager();
  $playlistRepository = $entityManager->getRepository(PlaylistForCompany::class);

  $playlistForCompany = $company->getPlaylistForCompany();  // 1. with getter
  $playlistForCompany = $playlistRepository->find(...);     // 2. with repository

  $form = $this->createForm(PlaylistForCompanyType::class, $playlistForCompany);
  $form->handleRequest($request);
  ...
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...