Home > OS >  Entity object not found by the @ParamConverter annotation
Entity object not found by the @ParamConverter annotation

Time:12-10

I'm getting this error in a controller that was previously working.

I have added some new Controllers (with different route prefix) so I guess the error might come from those new routes generated, but, honestly, I'm quite puzzled with how this can error could appear in a controller that has been long time unaltered.

This is my controller code:

ContractController.php

/**
 * @Route("/contract")
 */
class ContractController extends AbstractController
{
    /**
     * @Route("/edit/{id}", name="contract_edit", methods={"GET","POST"})
     */
    public function edit(Request $request, DocumentManagerService $dm, EventDispatcherInterface $dispatcher, Contract $contract): Response
    {
}

I get this error when accesing /contract/edit/1234:

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

If I add a @ParamConverter annotation, like this:

 * @ParamConverter("contract", options={"mapping": {"id"   : "id"}})

I get the same error. This same error occurs with other routes in the same controller, as I say all of them were working previously.

If I debug:router in console, I get hits routed prefixed with /contract, all of them are in this controller.

    contract_debug                     GET        ANY      ANY    /contract/debugcontract/show/{id}                                                 
    contract_debug_edit                GET|POST   ANY      ANY    /contract/debugcontract/edit/{id}                                                 
    contract_debug_renew               GET|POST   ANY      ANY    /contract/debugcontract/renew/{id}                                                
    contract_index                     GET        ANY      ANY    /contract/list                                                                    
    contract_new                       GET|POST   ANY      ANY    /contract/new/{client_id}                                                         
    contract_edit                      GET|POST   ANY      ANY    /contract/edit/{id}                                                               
    contract_add_payment               GET|POST   ANY      ANY    /contract/addpayment/{id}/{renew}/{cardid}                                        
    contract_payment_delete            GET        ANY      ANY    /contract/deletepayment/{id}                                                      
    contract_show                      GET        ANY      ANY    /contract/show/{id}                                                               
    contract_send_and_block            GET        ANY      ANY    /contract/send/{id}                                                               
    contract_protect                   GET        ANY      ANY    /contract/protect/{id}/{protect}                                                  
    contract_generate_invoice          GET        ANY      ANY    /contract/invoice/{id}/{send}

CodePudding user response:

I found the error, it had nothing to do with routes.

I created a new ContractRepository class for this entity, and copied/pasted the base code, resulting in this:

class ContractRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, Client::class);
    }
}

I was sending another entity class to the constructor, it should be Contract, not Client.

  • Related