This is documentation for Kohana v2.3.x.

Table of Contents
Statusstub
TodoWrite me

Request Helper

A helper designed to retrieve all kinds of information on the current request.

Methods

referrer()

referrer($default = FALSE) returns the HTTP referrer, or the default if the referrer is not set. It takes:

Example:

echo request::referrer();

It could result as:

http://www.google.com/search?hl=en&q=kohana&btnG=Google+Search

is_ajax()

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()

method() returns current HTTP request method (GET, POST, PUT, DELETE for example)

Example:

echo request::method();

It could result as:

get

accepts()

accepts($type = NULL, $explicit_check = FALSE) returns boolean of whether client accepts content type. It takes:

Example:

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()

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.

Example:

echo request::preferred_accept(array('xhtml', 'xml'));

It could result as:

xhtml

accepts_at_quality()

accepts_at_quality($type = NULL, $explicit_check = FALSE) returns quality factor at which the client accepts content type.

Example:

echo request::accepts_at_quality('image/jpg');

It could result as:

0.8