[TYPO3-german] Re: Extbase, Object to array?

David Brünner david.bruenner at t-online.de
Tue Jun 27 09:58:09 CEST 2017


public function queryResultToArray(QueryResult $queryResult, $fields = 'bezeichnung', $addemptyoption = true, $emptyoptionname = '') {
		$result = [];
		if ($addemptyoption) $result[0] = $emptyoptionname;
		while ($queryResult->valid()) {
			$obj = $queryResult->current();
			if (gettype($fields) == 'array') {
				$resultString = '';
				foreach ($fields as $field) {
					$method = 'get' . ucfirst($field);
					if (method_exists($obj, $method)) {
						$resultString .= $obj->{$method}() . ', ';
					}
				}
				$result[$obj->getUid()] = substr($resultString, 0, -2);
			} else {
				$method = 'get' . ucfirst($fields);
				if (method_exists($obj, $method)) {
					$result[$obj->getUid()] = $obj->{$method}();
				}
			}
			$queryResult->next();
		}
		return $result;
	}


More information about the TYPO3-german mailing list