Files
myep/src/Htmx/HxRedirectResponse.php
T
Björn Fromme 83589ee677 feat: htmx powered requests, improved loading indicator
feat: loading indicator and htmx form submit
2026-03-16 11:59:10 +01:00

33 lines
939 B
PHP

<?php
namespace App\Htmx;
use Symfony\Component\HttpFoundation\Response;
class HxRedirectResponse extends Response
{
/**
* Creates an HTMX redirect response.
*
* Constructs a response that instructs the HTMX client to navigate to the
* specified URL. The response includes the HX-Redirect header with the target
* URL. Optionally includes HX-Retarget header if a different target element
* is specified for the response content.
*
* @param string $url The URL to redirect to
* @param string|null $retarget Optional CSS selector for the target element
*/
public function __construct(string $url, ?string $retarget = null)
{
$headers = [
'HX-Redirect' => $url,
];
if (null !== $retarget) {
$headers['HX-Retarget'] = $retarget;
}
return parent::__construct(null, Response::HTTP_OK, $headers);
}
}