@ParamConverter 注释找不到的问题 Symfony 5 对象

Issues Symfony 5 object not found by the @ParamConverter annotation

我试图创建一个 edit/delete 实体对象的函数,但我遇到了这个问题

App\Entity\Courts object not found by the @ParamConverter annotation.

{slug} :获取 'categories'

的类型

{action} : 获取动作(删除或编辑)-删除作品

{id} : 获取对象的id

这里是造成问题的部分:

/**
 * @Route("/admin/{slug}/{action}/{id}", name="{slug}_{action}")
 */
public function delete(Courts $courts, Domains $domains, Request $request, $slug, $action, $id)
{
    switch ($slug) {
        case 'courts':
            $repos = $this->getDoctrine()->getRepository(Courts::class);
            $form = $this->createForm(ECategoriesFormType::class, $courts);
            break;
        case 'domains':
            $repos = $this->getDoctrine()->getRepository(Domains::class);
            $form = $this->createForm(ECategoriesFormType::class, $domains);
            break;
        default:
            // will redirect to admin page if user try to bypass by url with bad slug
            return $this->redirectToRoute('admin');
            break;
    }
}

我的问题已解决,这是我的解决方案:

它动态生成一个 url 像 admin/courts/add/edit/2admin/domains/delete/3

    /**
     * @Route("/admin/{slug}/{action}/{id}", name="{slug}_{action}")
     */
  public function delete(CourtsRepository $courtsRepository,
                           DomainsRepository $domainsRepository,
                           Request $request, $slug, $action, $id)
    {
        /*
         *  Get the repos for edit or delete update
         *  Check if the action is edit to get the execute query
         */
        switch ($slug) {
            case 'courts':
                $repos = $this->getDoctrine()->getRepository(Courts::class);
                $form = ($action == "edit") ? $this->createForm(ACategoriesFormType::class, $courtsRepository->find($id)) : false;
                break;
            case 'domains':
                $repos = $this->getDoctrine()->getRepository(Domains::class);
                $form = ($action == "edit") ? $this->createForm(ACategoriesFormType::class, $domainsRepository->find($id)): false;
                break;
            default:
                // will redirect to admin page if user try to bypass by url with bad slug
                return $this->redirectToRoute('admin');
                break;
        }
   }