lithium\action\Request::get()

public method

This method allows easy extraction of any request data using a prefixed key syntax. By passing keys in the form of 'prefix:key', it is possible to query different information of various different types, including GET and POST data, and server environment variables. The full list of prefixes is as follows:

  • 'data': Retrieves values from POST data.
  • 'params': Retrieves query parameters returned from the routing system.
  • 'query': Retrieves values from GET data.
  • 'env': Retrieves values from the server or environment, such as 'env:https', or custom environment values, like 'env:base'. See the env() method for more info.
  • 'http': Retrieves header values (i.e. 'http:accept'), or the HTTP request method (i.e. 'http:method').

This method is used in several different places in the framework in order to provide the ability to act conditionally on different aspects of the request. See Media::type() (the section on content negotiation) and the routing system for more information.

Note: All keys should be lower-cased, even when getting HTTP headers.

Parameters

  • string $key

    A prefixed key indicating what part of the request data the requested value should come from, and the name of the value to retrieve, in lower case.

Returns

string

Returns the value of a GET, POST, routing or environment variable, or an HTTP header or method name.

Source

	public function get($key) {
		list($var, $key) = explode(':', $key);

		switch (true) {
			case in_array($var, ['params', 'data', 'query']):
				return isset($this->{$var}[$key]) ? $this->{$var}[$key] : null;
			case ($var === 'env'):
				return $this->env(strtoupper($key));
			case ($var === 'http' && $key === 'method'):
				return $this->env('REQUEST_METHOD');
			case ($var === 'http'):
				return $this->env('HTTP_' . strtoupper($key));
		}
	}