This is documentation for Kohana v2.3.x.
Status | stub |
---|---|
Todo | Write me |
A helper designed to retrieve all kinds of information on the current request.
referrer($default = FALSE)
returns the HTTP referrer, or the default if the referrer is not set. It takes:
$default
default to return - default FALSEExample:
echo request::referrer();
It could result as:
http://www.google.com/search?hl=en&q=kohana&btnG=Google+Search
is_ajax()
tests if the current request is an AJAX request by checking the X-Requested-With HTTP request header that most popular JS frameworks now set for AJAX calls.
Example:
We can use this method to detect ajax requests in the controller and disable the view template so we can output a properly formatted JSON response.
$animals = array('dog', 'cat', 'mouse'); if (request::is_ajax()) { $this->auto_render = FALSE; // disable auto render echo json_encode($animals); }
method()
returns current HTTP request method (GET, POST, PUT, DELETE for example)
Example:
echo request::method();
It could result as:
get
accepts($type = NULL, $explicit_check = FALSE)
returns boolean of whether client accepts content type. It takes:
$type
the content type$explicit_check
set to TRUE to disable wildcard checking - default FALSEExample:
if (request::accepts('xhtml') && request::accepts('xml') && request::accepts('rss') && request::accepts('atom')) { echo 'Client accepts all of them'; } else { echo 'Client doesn\'t accept one/several of xhtml, xml, rss, atom'; }
It could result in HTML as:
Client accepts all of them
preferred_accept($types, $explicit_check = FALSE)
compare the q values for given array of content types and return the one with the highest value. If items are found to have the same q value, the first one encountered in the given array wins. If all items in the given array have a q value of 0, FALSE is returned.
$types
array of the content types$explicit_check
sets to TRUE to disable wildcard checking - default FALSEExample:
echo request::preferred_accept(array('xhtml', 'xml'));
It could result as:
xhtml
accepts_at_quality($type = NULL, $explicit_check = FALSE)
returns quality factor at which the client accepts content type.
$type
content type (e.g. “image/jpg”, “jpg”)$explicit_check
sets to TRUE to disable wildcard checking - default FALSEExample:
echo request::accepts_at_quality('image/jpg');
It could result as:
0.8