Class yii\db\JsonExpression
Inheritance | yii\db\JsonExpression |
---|---|
Implements | JsonSerializable, yii\db\ExpressionInterface |
Available since version | 2.0.14 |
Class JsonExpression represents data that should be encoded to JSON.
For example:
new JsonExpression(['a' => 1, 'b' => 2]); // will be encoded to '{"a": 1, "b": 2}'
Protected Properties
隐藏继承的属性 Hide inherited properties
属性Property | 类型 Type | 简介 Description | 定义在 Defined By |
---|---|---|---|
$type | string|null | Type of JSON, expression should be casted to. | yii\db\JsonExpression |
$value | mixed | The value to be encoded to JSON. | yii\db\JsonExpression |
Public Methods
隐藏继承的方法 Hide inherited methods
方法 Method | 简介 Description | 定义在 Defined By |
---|---|---|
__construct() | JsonExpression constructor. | yii\db\JsonExpression |
getType() | yii\db\JsonExpression | |
getValue() | yii\db\JsonExpression | |
jsonSerialize() | Specify data which should be serialized to JSON | yii\db\JsonExpression |
常量 Constants
隐藏继承的常量 Hide inherited constants
常量 Constant | 值 Value | 简介 Description | 定义在 Defined By |
---|---|---|---|
TYPE_JSON | 'json' | yii\db\JsonExpression | |
TYPE_JSONB | 'jsonb' | yii\db\JsonExpression |
属性详情 Property Details
Type of JSON, expression should be casted to. Defaults to null
, meaning
no explicit casting will be performed.
This property will be encountered only for DBMSs that support different types of JSON.
For example, PostgreSQL has json
and jsonb
types.
The value to be encoded to JSON. The value must be compatible with [\yii\helpers\Json::encode()|Json::encode()]] input requirements.
方法详情 Method Details
JsonExpression constructor.
请参阅 $type.
public void __construct ( $value, $type = null ) | ||
$value | mixed | The value to be encoded to JSON. The value must be compatible with [\yii\helpers\Json::encode()|Json::encode()]] requirements. |
$type | string|null | The type of the JSON. See yii\db\JsonExpression::$type |
请参阅 $type.
public null|string getType ( ) | ||
return | null|string | The type of JSON |
---|
请参阅 $value.
public mixed getValue ( ) |
Specify data which should be serialized to JSON
public mixed jsonSerialize ( ) | ||
return | mixed | Data which can be serialized by json_encode, which is a value of any type other than a resource. |
---|---|---|
throws | yii\base\InvalidConfigException | when JsonExpression contains QueryInterface object |