$serializer = $this->get('serializer');
$recipe = $this->getDoctrine()
->getRepository(Recipe::class)
->find($id);
if (!$recipe) {
throw $this->createNotFoundException('The recipe does not exist');
}
return $this->render('recipe/recipe.html.twig', [
// A JSON string also works
'props' => $serializer->serialize(
$this->dispatcher->dispatch($event, KernelEvents::CONTROLLER_ARGUMENTS);
$controller = $event->getController();
$arguments = $event->getArguments();
// call controller
$response = $controller(...$arguments);
// view
if (!$response instanceof Response) {
$event = new ViewEvent($this, $request, $type, $response);
$this->dispatcher->dispatch($event, KernelEvents::VIEW);
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
{
$request->headers->set('X-Php-Ob-Level', (string) ob_get_level());
try {
return $this->handleRaw($request, $type);
} catch (\Exception $e) {
if ($e instanceof RequestExceptionInterface) {
$e = new BadRequestHttpException($e->getMessage(), $e);
}
if (false === $catch) {
Request::setTrustedHosts(explode(',', $trustedHosts));
}
$kernel = new Kernel($_SERVER['APP_ENV'] ?? 'dev', $_SERVER['APP_DEBUG'] ?? ('prod' !== ($_SERVER['APP_ENV'] ?? 'dev')));
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
NotFoundHttpException |
---|
Symfony\Component\HttpKernel\Exception\NotFoundHttpException: The recipe does not exist at vendor/symfony/framework-bundle/Controller/ControllerTrait.php:293 at Symfony\Bundle\FrameworkBundle\Controller\Controller->createNotFoundException('The recipe does not exist') (src/Controller/RecipeController.php:39) at App\Controller\RecipeController->recipeAction('carbonara', object(Request)) (vendor/symfony/http-kernel/HttpKernel.php:158) at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1) (vendor/symfony/http-kernel/HttpKernel.php:80) at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true) (vendor/symfony/http-kernel/Kernel.php:201) at Symfony\Component\HttpKernel\Kernel->handle(object(Request)) (public/index.php:34) |