AjaxResponseTrait
Trait to allow AJAX response generation.
Dependencies:
- \VuFind\I18n\Translator\TranslatorAwareTrait
- Injection of $this->ajaxManager (for some functionality)
Tags
Table of Contents
- $ajaxManager : PluginManager
- AJAX Handler plugin manager
- callAjaxMethod() : Response
- Call an AJAX method and turn the result into a response.
- formatContent() : string
- Format the content of the AJAX response based on the response type.
- getAjaxResponse() : Response
- Send output data and exit.
- getExceptionResponse() : Response
- Turn an exception into error response.
Properties
$ajaxManager
AJAX Handler plugin manager
protected
PluginManager
$ajaxManager
= null
Methods
callAjaxMethod()
Call an AJAX method and turn the result into a response.
protected
callAjaxMethod(string $method[, string $type = 'application/json' ]) : Response
Parameters
- $method : string
-
AJAX method to call
- $type : string = 'application/json'
-
Content type to output
Return values
Response —formatContent()
Format the content of the AJAX response based on the response type.
protected
formatContent(string $type, mixed $data, int $httpCode) : string
Parameters
- $type : string
-
Content-type of output
- $data : mixed
-
The response data
- $httpCode : int
-
A custom HTTP Status Code
Tags
Return values
string —getAjaxResponse()
Send output data and exit.
protected
getAjaxResponse(string $type, mixed $data[, int $httpCode = null ]) : Response
Parameters
- $type : string
-
Content type to output
- $data : mixed
-
The response data
- $httpCode : int = null
-
A custom HTTP Status Code
Tags
Return values
Response —getExceptionResponse()
Turn an exception into error response.
protected
getExceptionResponse(string $type, Exception $e) : Response
Parameters
- $type : string
-
Content type to output
- $e : Exception
-
Exception to output.