lithium\net\http\Request::queryString()

public method

Get the full query string queryString.

Parameters

  • array $params
  • string $format

Returns

string

Source

	public function queryString($params = [], $format = null) {
		$result = [];
		$query = [];

		foreach (array_filter([$this->query, $params]) as $querySet) {
			if (is_string($querySet)) {
				$result[] = $querySet;
				continue;
			}
			$query = array_merge($query, $querySet);
		}
		$query = array_filter($query);

		if ($format) {
			$q = null;
			foreach ($query as $key => $value) {
				if (!is_array($value)) {
					$q .= Text::insert($format, [
						'key' => urlencode($key),
						'value' => urlencode($value)
					]);
					continue;
				}
				foreach ($value as $val) {
					$q .= Text::insert($format, [
						'key' => urlencode("{$key}[]"),
						'value' => urlencode($val)
					]);
				}
			}
			$result[] = substr($q, 0, -1);
		} else {
			$result[] = http_build_query($query);
		}

		$result = array_filter($result);
		return $result ? "?" . join("&", $result) : null;
	}