This page is a translated version of the page Manual:ApiResult.php and the translation is 17% complete.

The ApiResult class represents the result of the API operations.

It simply wraps a nested array() structure, adding some functions to simplify array's modifications. As various modules execute, they add different pieces of information to this result, structuring it as it will be given to the client.

Each subarray may either be a dictionary - key-value pairs with unique keys, or lists, where the items are added using $data[] = $value notation.

There are two special key values that change how XML output is generated:

  • '_element' - This key sets the tag name for the rest of the elements in the current array. It is only inserted if the formatter returned true for getNeedsRawData()
  • '*' - This key has special meaning only to the XML formatter, and is output as is for all others. In XML it becomes the content of the current element.



addValue ( $path, $name, $value, $flags = 0 )

Add value to the output data at the given path.

Path can be an indexed array, each element specifying the branch at which to add the new value. Setting $path to array('a','b','c') is equivalent to data['a']['b']['c'] = $value. If $path is null, the value will be inserted at the data root. If $name is empty, the $value is added as a next list element data[] = $value.


class ApiFoo extends ApiBase {
	public function execute() {
		$apiResult = $this->getResult();
		$r['result'] = 'Success';
		$r['bar'] = 'baz';
		$apiResult->addValue( null, $this->getModuleName(), $r );

	public function getResultProperties() {
		return array(
			'foo' => array(
				'result' => array(
					ApiBase::PROP_TYPE => array(
				'bar' => array(
					ApiBase::PROP_TYPE => 'string',
					ApiBase::PROP_NULLABLE => true

Voir aussi