Home > database >  App\\Entity\\Project object not found by the @ParamConverter annotation
App\\Entity\\Project object not found by the @ParamConverter annotation

Time:10-20

Bit of an obscure one this. I'm reading that Symfony get's muddled when dealing with more than one route of a similar pattern. Here goes, this is what I've tried thus far:-

For starters, I hit the endpoint: https://127.0.0.1:8000/api/contracts/12345/new which returns the 404 error in full:-

{type: "https://tools.ietf.org/html/rfc2616#section-10", title: "An error occurred", status: 404,…}
class
: 
"Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException"
detail
: 
"App\\Entity\\Project object not found by the @ParamConverter annotation."
status
: 
404
title
: 
"An error occurred"
trace
: 
[{namespace: "", short_class: "", class: "", type: "", function: "",…},…]
type
: 
"https://tools.ietf.org/html/rfc2616#section-10"

Here's a snapshot of my URL patterns:-

docker-compose exec app bin/console debug:router
new_contract          POST     ANY      ANY    /api/contracts/{id}/new                                                    
api_edit_project      POST     ANY      ANY    /api/contracts/{id}/edit

They're very similar but I'm using the new endpoint from above. Here's the controller:-

/**
 * @Route("/api")
 */
class ContractController extends BaseApiController
{
   /**
   * @Post ("/contracts/{id}/new", name="new_contract")
   */
   public function postNewContractAction(){
      // -- we don't hit this method at all
   } 
   
   /**
   * @Post ("/contracts/{id}/edit", name="api_edit_project")
   */
   public function postEditContractAction(){}

}

Further to this, I've tried moving the controller methods around in terms of ordering, but this has no effect.

Any ideas?

CodePudding user response:

As statet in the Symfony Documentation, receiving a 404 Error, when trying to fetch an object by it's id automatically using the paramConverter magic, this usually means there is no data for that id.

  • If no Post object is found, a 404 Response is generated;

I suspect there is no Project with id=12345.

Why are you asking for an {id} in the /new route, actually? To my understanding you would not have an ID in that case, yet.


I always try to set the parameters at last position in routes, as it may avoid route collisions.

  • Related