Class yii\db\JsonExpression

继承yii\db\JsonExpression
实现JsonSerializable, yii\db\ExpressionInterface
可用自版本2.0.14
源代码 https://github.com/yiisoft/yii2/blob/master/framework/db/JsonExpression.php

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}'

受保护的属性

隐藏继承的属性

属性类型描述定义在
$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

公共方法

隐藏继承的方法

方法描述定义在
__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

常量

隐藏继承的常量

常量描述定义在
TYPE_JSON 'json' yii\db\JsonExpression
TYPE_JSONB 'jsonb' yii\db\JsonExpression

属性详情

$type protected 属性

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.

protected string|null $type null
$value protected 属性

The value to be encoded to JSON. The value must be compatible with [\yii\helpers\Json::encode()|Json::encode()]] input requirements.

protected mixed $value null

方法详情

__construct() public 方法

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

getType() public 方法

参见 $type.

public null|string getType ( )
return null|string

The type of JSON

getValue() public 方法

参见 $value.

public mixed getValue ( )
jsonSerialize() public 方法 (可用自版本: 2.0.14.2)

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