class PjaxResponseNegotiator (View source)

Handle the X-Pjax header that AJAX responses may provide, returning the fragment, or, in the case of non-AJAX form submissions, redirecting back to the submitter.

X-Pjax ensures that users won't end up seeing the unstyled form HTML in their browser.

If a JS error prevents the Ajax overriding of form submissions from happening.

It also provides better non-JS operation.

Caution: This API is volatile, and might eventually be replaced by a generic action helper system for controllers.

Properties

protected array $callbacks

See respond()

protected $response
protected $fragmentOverride

Overridden fragments (if any). Otherwise uses fragments from the request.

Methods

public
__construct(array $callbacks = [], HTTPResponse $response = null)

No description

public
getResponse()

No description

public
setResponse($response)

No description

public
respond(HTTPRequest $request, array $extraCallbacks = [])

Out of the box, the handler "CurrentForm" value, which will return the rendered form.

public
setCallback(string $fragment, callable $callback)

No description

public
$this
setFragmentOverride(array $fragments)

Set up fragment overriding - will completely replace the incoming fragments.

public
array
getFragmentOverride()

No description

Details

__construct(array $callbacks = [], HTTPResponse $response = null)

No description

Parameters

array $callbacks
HTTPResponse $response

An existing response to reuse (optional)

getResponse()

No description

setResponse($response)

No description

Parameters

$response

HTTPResponse respond(HTTPRequest $request, array $extraCallbacks = [])

Out of the box, the handler "CurrentForm" value, which will return the rendered form.

Non-Ajax calls will redirect back.

Parameters

HTTPRequest $request
array $extraCallbacks

List of anonymous functions or callables returning either a string or HTTPResponse, keyed by their fragment identifier. The 'default' key can be used as a fallback for non-ajax responses.

Return Value

HTTPResponse

Exceptions

HTTPResponse_Exception

setCallback(string $fragment, callable $callback)

No description

Parameters

string $fragment
callable $callback

$this setFragmentOverride(array $fragments)

Set up fragment overriding - will completely replace the incoming fragments.

Parameters

array $fragments

Fragments to insert.

Return Value

$this

array getFragmentOverride()

No description

Return Value

array