Reputation: 8523
I just discovered the ParamConverter syntax.
Here is what the doc says :
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; /** * @Route("/blog/{id}") * @ParamConverter("post", class="SensioBlogBundle:Post") */ public function showAction(Post $post) { }
Several things happen under the hood:
- ...
- If no Post object is found, a 404 Response is generated;
- If a Post object is found, a new post request attribute is defined...
- ...
I tried this exact thing and it works fine if the id is known but if it is not then I get this Symfony error :
AppBundle\Entity\MyCustomEntity object not found.
Shouldn't I get a 404 Exception, which redirect me to my custom 404 page ?
Additionnaly, I tried what this post suggested, but the condition is not even read, and the same exact "object not found" error is shown again.
Is there any other way to get this working ?
Upvotes: 1
Views: 2329
Reputation: 1031
symfony 6 Param Converter & 404's ==> composer require sensio/framework-extra-bundle
#[Route('/blog/{date}/{slug}/comments/{comment_slug}')]
#[ParamConverter('post', options: ['mapping' => ['date' => 'date', 'slug' => 'slug']])]
#[ParamConverter('comment', options: ['mapping' => ['comment_slug' => 'slug']])]
public function showComment(Post $post, Comment $comment)
{
}
Upvotes: 0
Reputation: 8162
Shouldn't I get a 404 Exception, which redirect me to my custom 404 page ?
Yes, in prod
environment
In dev
environment, you have some explanation about the error to help you debugging.
Upvotes: 3