PHP Класс yii\web\JsonResponseFormatter

It is used by Response to format response data. To configure properties like [[encodeOptions]] or [[prettyPrint]], you can configure the response application component like the following: php 'response' => [ ... 'formatters' => [ \yii\web\Response::FORMAT_JSON => [ 'class' => 'yii\web\JsonResponseFormatter', 'prettyPrint' => YII_DEBUG, // use "pretty" output in debug mode ... ], ], ],
С версии: 2.0
Автор: Qiang Xue ([email protected])
Наследование: extends yii\base\Component, implements yii\web\ResponseFormatterInterface
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$encodeOptions the encoding options passed to [[Json::encode()]]. For more details please refer to . Default is JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE. This property has no effect, when [[useJsonp]] is true.
$prettyPrint whether to format the output in a readable "pretty" format. This can be useful for debugging purpose. If this is true, JSON_PRETTY_PRINT will be added to [[encodeOptions]]. Defaults to false. This property has no effect, when [[useJsonp]] is true.
$useJsonp whether to use JSONP response format. When this is true, the [[Response::data|response data]] must be an array consisting of data and callback members. The latter should be a JavaScript function name while the former will be passed to this function as a parameter.

Открытые методы

Метод Описание
format ( Response $response ) Formats the specified response.

Защищенные методы

Метод Описание
formatJson ( Response $response ) Formats response data in JSON format.
formatJsonp ( Response $response ) Formats response data in JSONP format.

Описание методов

format() публичный Метод

Formats the specified response.
public format ( Response $response )
$response Response the response to be formatted.

formatJson() защищенный Метод

Formats response data in JSON format.
protected formatJson ( Response $response )
$response Response

formatJsonp() защищенный Метод

Formats response data in JSONP format.
protected formatJsonp ( Response $response )
$response Response

Описание свойств

$encodeOptions публичное свойство

the encoding options passed to [[Json::encode()]]. For more details please refer to . Default is JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE. This property has no effect, when [[useJsonp]] is true.
С версии: 2.0.7
public $encodeOptions

$prettyPrint публичное свойство

whether to format the output in a readable "pretty" format. This can be useful for debugging purpose. If this is true, JSON_PRETTY_PRINT will be added to [[encodeOptions]]. Defaults to false. This property has no effect, when [[useJsonp]] is true.
С версии: 2.0.7
public $prettyPrint

$useJsonp публичное свойство

whether to use JSONP response format. When this is true, the [[Response::data|response data]] must be an array consisting of data and callback members. The latter should be a JavaScript function name while the former will be passed to this function as a parameter.
public $useJsonp