lithium\data\Entity::to()

public method

Converts the data in the record set to a different format, i.e. an array.

Parameters

  • string $format

    Currently only array.

  • array $options

    Options for converting:

    • 'indexed' boolean: Allows to control how converted data of nested collections is keyed. When set to true will force indexed conversion of nested collection data. By default false which will only index the root level.

Returns

mixed

Source

	public function to($format, array $options = []) {
		$defaults = ['handlers' => []];
		$options += $defaults;

		$options['handlers'] += $this->_handlers;
		switch ($format) {
			case 'array':
				$data = $this->_updated;
				$rel = array_map(function($obj) { return $obj->data(); }, $this->_relationships);
				$data = $rel + $data;
				$options['indexed'] = isset($options['indexed']) ? $options['indexed'] : false;
				$result = Collection::toArray($data, $options);
			break;
			case 'string':
				$result = $this->__toString();
			break;
			default:
				$result = $this;
			break;
		}
		return $result;
	}