Symfony framework allows using profiler that gives debug information about various application parts during development. This tutorial explains how to enable profiler using URL query parameter in Symfony 7 application.
Profiler collects a lot of information and can slow down the application. We can set profiler.collect
option to false
to disable the profiler by default. The profiler.collect_parameter
option allows specifying the name of URL query parameter that can enable the profiler for requests.
framework:
profiler:
collect: false
collect_parameter: 'profiler'
In our case, profiler will be only enabled if we specify the query parameter profiler
with value 1
in URL (e.g. http://localhost?profiler=1
).
Controller and Twig template for testing:
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
class TestController extends AbstractController
{
#[Route('/')]
public function index(): Response
{
return $this->render('test/index.html.twig');
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Symfony</title>
</head>
<body>
</body>
</html>
Leave a Comment
Cancel reply