Alpha ZealPHP is early-stage and under active development. APIs may change between minor versions until v1.0. Feedback and bug reports welcome on GitHub.
API Index — Namespaces, Packages, Reports, Indices

HtmxResponse
in package

Fluent builder for htmx response headers (HX-*).

Obtain via Response::htmx() and chain setter calls; the headers are queued into the parent Response's headersList and emitted on the next flush().

$response->htmx()->retarget('#alerts')->reswap('afterbegin')->trigger('itemSaved');

All HX-* header values are validated for CRLF/NUL injection before queuing; invalid values trigger an E_USER_WARNING and are silently dropped (matching the behaviour of Response::header()).

Table of Contents

Properties

$response  : Response

Methods

__construct()  : mixed
location()  : static
HX-Location — client-side redirect that does not do a full page reload.
oob()  : string
Wrap $html in an OOB swap element.
pushUrl()  : static
HX-Push-Url — push a new URL onto the browser history stack.
redirect()  : static
HX-Redirect — client-side redirect (no full page reload).
refresh()  : static
HX-Refresh — set to "true" to trigger a full client-side page refresh.
replaceUrl()  : static
HX-Replace-Url — replace the current URL in the location bar without adding a history entry. Pass false (as string "false") to prevent.
reselect()  : static
HX-Reselect — CSS selector choosing which part of the response body is swapped in (overrides an existing hx-select on the element).
reswap()  : static
HX-Reswap — override the swap strategy declared on the triggering element.
retarget()  : static
HX-Retarget — CSS selector that redirects the swap to a different element.
trigger()  : static
HX-Trigger — trigger one or more client-side events after the swap.
triggerAfterSettle()  : static
HX-Trigger-After-Settle — same as trigger() but fires after the settle step.
triggerAfterSwap()  : static
HX-Trigger-After-Swap — same as trigger() but fires after the swap step.
emit()  : void

Properties

Methods

location()

HX-Location — client-side redirect that does not do a full page reload.

public location(string $urlOrJson) : static

Accepts a URL string or a JSON-encoded location object (e.g. {"path":"/page","target":"#content"}).

Parameters
$urlOrJson : string
Return values
static

oob()

Wrap $html in an OOB swap element.

public static oob(string $id, string $html[, string $swap = 'true' ][, string $tag = 'div' ]) : string

Generates a fragment like <div id="$id" hx-swap-oob="$swap">$html</div>. Append the return value to any response body to perform an out-of-band swap without an additional round-trip.

Parameters
$id : string

The CSS id of the target element (without #).

$html : string

Inner HTML to inject.

$swap : string = 'true'

hx-swap-oob value (default: "true" → innerHTML).

$tag : string = 'div'

Wrapper element tag (default: div).

Return values
string

pushUrl()

HX-Push-Url — push a new URL onto the browser history stack.

public pushUrl(string $url) : static

Pass false (as string "false") to prevent pushing.

Parameters
$url : string
Return values
static

redirect()

HX-Redirect — client-side redirect (no full page reload).

public redirect(string $url) : static
Parameters
$url : string
Return values
static

refresh()

HX-Refresh — set to "true" to trigger a full client-side page refresh.

public refresh([bool $refresh = true ]) : static
Parameters
$refresh : bool = true
Return values
static

replaceUrl()

HX-Replace-Url — replace the current URL in the location bar without adding a history entry. Pass false (as string "false") to prevent.

public replaceUrl(string $url) : static
Parameters
$url : string
Return values
static

reselect()

HX-Reselect — CSS selector choosing which part of the response body is swapped in (overrides an existing hx-select on the element).

public reselect(string $selector) : static
Parameters
$selector : string
Return values
static

reswap()

HX-Reswap — override the swap strategy declared on the triggering element.

public reswap(string $strategy) : static

Valid values: innerHTML, outerHTML, beforebegin, afterbegin, beforeend, afterend, delete, none (and modifier suffixes such as innerHTML swap:1s).

Parameters
$strategy : string
Return values
static

retarget()

HX-Retarget — CSS selector that redirects the swap to a different element.

public retarget(string $selector) : static
Parameters
$selector : string
Return values
static

trigger()

HX-Trigger — trigger one or more client-side events after the swap.

public trigger(string $events) : static

Pass a single event name, a comma-separated list, or a JSON object for events with detail data (e.g. {"showMessage":{"level":"info"}}).

Parameters
$events : string
Return values
static

triggerAfterSettle()

HX-Trigger-After-Settle — same as trigger() but fires after the settle step.

public triggerAfterSettle(string $events) : static
Parameters
$events : string
Return values
static

triggerAfterSwap()

HX-Trigger-After-Swap — same as trigger() but fires after the swap step.

public triggerAfterSwap(string $events) : static
Parameters
$events : string
Return values
static

emit()

private emit(string $name, string $value) : void
Parameters
$name : string
$value : string
On this page