public toArray ( array $fields = [], array $expand = [], boolean $recursive = true ) : array | ||
$fields | array | the fields being requested. If empty, all fields as specified by [[fields()]] will be returned. |
$expand | array | the additional fields being requested for exporting. Only fields declared in [[extraFields()]] will be considered. |
$recursive | boolean | whether to recursively return array representation of embedded objects. |
return | array | the array representation of the object |
public function toArray(array $fields = [], array $expand = [], $recursive = true)
{
$data = [];
foreach ($this->resolveFields($fields, $expand) as $field => $definition) {
$data[$field] = is_string($definition) ? $this->{$definition} : call_user_func($definition, $this, $field);
}
if ($this instanceof Linkable) {
$data['_links'] = Link::serialize($this->getLinks());
}
return $recursive ? ArrayHelper::toArray($data) : $data;
}