What is the correct way to get values ​​from a query string in Kohana 3

Just curious, what is the Kohana way of getting variables from the query string?

The best I could come up with is parsing $ _GET var with the Arr class. Anyone have a better way to do this?

// foo?a=1&b=2
function action_welcome()
{
    echo('a = '.Arr::get($_GET, 'a', '0'));
    echo('b = '.Arr::get($_GET, 'b', '0'));
}
+5
source share
2 answers

This is pretty much the right way, I suggest you use NULL as the default instead of the string '0', wherever you are.

You can also use this function for any type of array, and not just for global vars, so instead of

$var = isset($arr['key']) ? $array['key'] : NULL

you just did (Kohana 3.0)

$var = Arr::get($arr, 'key', NULL);

or (Kohana 3.1 +)

$var = $request->query('key');
+6
source

, Arr:: get , Kohana,

Request::current->query('variable')

$this->request->query('variable')

,

+7

All Articles