@@ -217,9 +217,48 @@ user by dynamically rewriting the current page rather than loading entire new
|
217 | 217 | pages from a server.
|
218 | 218 |
|
219 | 219 | By default, the debug toolbar displays the information of the initial page load
|
220 |
| -and doesn't refresh after each AJAX request. However, you can set the |
221 |
| -``Symfony-Debug-Toolbar-Replace`` header to a value of ``'1'`` in the response to |
222 |
| -the AJAX request to force the refresh of the toolbar:: |
| 220 | +and doesn't refresh after each AJAX request. However, you can configure the |
| 221 | +toolbar to be refreshed after each AJAX request by enabling ``ajax_replace`` in the |
| 222 | +``web_profiler`` configuration: |
| 223 | + |
| 224 | +.. configuration-block:: |
| 225 | + |
| 226 | +.. code-block:: yaml |
| 227 | +
|
| 228 | +# config/packages/web_profiler.yaml |
| 229 | +web_profiler: |
| 230 | +toolbar: |
| 231 | +ajax_replace: true |
| 232 | +
|
| 233 | + .. code-block:: xml |
| 234 | +
|
| 235 | +<!-- config/packages/web_profiler.xml --> |
| 236 | +<?xml version="1.0" ?> |
| 237 | +<container xmlns="http://symfony.com/schema/dic/services" |
| 238 | +xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 239 | +xmlns:framework="http://symfony.com/schema/dic/symfony" |
| 240 | +xmlns:web-profiler="http://symfony.com/schema/dic/webprofiler" |
| 241 | +xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd |
| 242 | +http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> |
| 243 | +
|
| 244 | +<web-profiler:config> |
| 245 | +<web-profiler:toolbar ajax-replace="true"/> |
| 246 | +</web-profiler:config> |
| 247 | +</container> |
| 248 | +
|
| 249 | + .. code-block:: php |
| 250 | +
|
| 251 | +// config/packages/web_profiler.php |
| 252 | +use Symfony\Config\WebProfilerConfig; |
| 253 | +
|
| 254 | +return static function (WebProfilerConfig $profiler): void { |
| 255 | +$profiler->toolbar() |
| 256 | +->ajaxReplace(true); |
| 257 | +}; |
| 258 | +
|
| 259 | +If you need a more sophisticated solution, you can set the |
| 260 | +``Symfony-Debug-Toolbar-Replace`` header to a value of ``'1'`` in the response |
| 261 | +yourself:: |
223 | 262 |
|
224 | 263 | $response->headers->set('Symfony-Debug-Toolbar-Replace', '1');
|
225 | 264 |
|
@@ -228,31 +267,21 @@ production. To do that, create an :doc:`event subscriber </event_diser>`
|
228 | 267 | and listen to the :ref:`kernel.response <component-http-kernel-kernel-response>`
|
229 | 268 | event::
|
230 | 269 |
|
| 270 | +use Symfony\Component\DependencyInjection\Attribute\When; |
231 | 271 | use Symfony\Component\EventDiser\EventSubscriberInterface;
|
232 | 272 | use Symfony\Component\HttpKernel\Event\ResponseEvent;
|
233 | 273 | use Symfony\Component\HttpKernel\KernelInterface;
|
234 | 274 |
|
235 | 275 | // ...
|
236 | 276 |
|
| 277 | +#[When(env: 'dev')] |
237 | 278 | class MySubscriber implements EventSubscriberInterface
|
238 | 279 | {
|
239 |
| -public function __construct( |
240 |
| -private KernelInterface $kernel, |
241 |
| -) { |
242 |
| -} |
243 |
| - |
244 | 280 | // ...
|
245 | 281 |
|
246 | 282 | public function onKernelResponse(ResponseEvent $event): void
|
247 | 283 | {
|
248 |
| -if (!$this->kernel->isDebug()) { |
249 |
| -return; |
250 |
| -} |
251 |
| - |
252 |
| -$request = $event->getRequest(); |
253 |
| -if (!$request->isXmlHttpRequest()) { |
254 |
| -return; |
255 |
| -} |
| 284 | +// Your custom logic here |
256 | 285 |
|
257 | 286 | $response = $event->getResponse();
|
258 | 287 | $response->headers->set('Symfony-Debug-Toolbar-Replace', '1');
|
|
0 commit comments