views:

102

answers:

1

Just curious as to what is the 'Kohana' way of getting variables from the query string?

The best that I could come up with is parsing the $_GET var with the Arr class. Anybody 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'));
}
+3  A: 

That's pretty much the right way, I'd only suggest you to use NULL as default instead of string '0' where ever you can.

You can also use this function for any kind of array, not only global vars, so instead of

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

you just do

$var = Arr::get($arr, 'key', NULL);
Kemo
Passing NULL as the 3rd argument is superfluous.
The Pixel Developer
@The Pixel Developer exactly, as it's the default value anyways; I was only referring to it as a better practice than passing '0' :)
Kemo