PHP 인터페이스 yii\base\Arrayable

부터: 2.0
저자: Qiang Xue ([email protected])
파일 보기 프로젝트 열기: yiisoft/yii2 0 사용 예제들

공개 메소드들

메소드 설명
extraFields ( ) : array Returns the list of additional fields that can be returned by Arrayable::toArray in addition to those listed in Arrayable::fields.
fields ( ) : array Returns the list of fields that should be returned by default by Arrayable::toArray when no specific fields are specified.
toArray ( array $fields = [], array $expand = [], boolean $recursive = true ) : array Converts the object into an array.

메소드 상세

extraFields() 공개 메소드

This method is similar to Arrayable::fields except that the list of fields declared by this method are not returned by default by Arrayable::toArray. Only when a field in the list is explicitly requested, will it be included in the result of Arrayable::toArray.
또한 보기: toArray()
또한 보기: fields()
public extraFields ( ) : array
리턴 array the list of expandable field names or field definitions. Please refer to [[fields()]] on the format of the return value.

fields() 공개 메소드

A field is a named element in the returned array by Arrayable::toArray. This method should return an array of field names or field definitions. If the former, the field name will be treated as an object property name whose value will be used as the field value. If the latter, the array key should be the field name while the array value should be the corresponding field definition which can be either an object property name or a PHP callable returning the corresponding field value. The signature of the callable should be: php function ($model, $field) { return field value } For example, the following code declares four fields: - email: the field name is the same as the property name email; - firstName and lastName: the field names are firstName and lastName, and their values are obtained from the first_name and last_name properties; - fullName: the field name is fullName. Its value is obtained by concatenating first_name and last_name. php return [ 'email', 'firstName' => 'first_name', 'lastName' => 'last_name', 'fullName' => function ($model) { return $model->first_name . ' ' . $model->last_name; }, ];
또한 보기: toArray()
public fields ( ) : array
리턴 array the list of field names or field definitions.

toArray() 공개 메소드

Converts the object into an array.
public toArray ( array $fields = [], array $expand = [], boolean $recursive = true ) : array
$fields array the fields that the output array should contain. Fields not specified in [[fields()]] will be ignored. If this parameter is empty, all fields as specified in [[fields()]] will be returned.
$expand array the additional fields that the output array should contain. Fields not specified in [[extraFields()]] will be ignored. If this parameter is empty, no extra fields will be returned.
$recursive boolean whether to recursively return array representation of embedded objects.
리턴 array the array representation of the object