Php – CodeIgniter – Routing urls with GET Variables

codeignitercodeigniter-3codeigniter-routingphp

I checked the similar questions out there, but those doesnt seem to help.

I have an email verification like, that is to be routed in CodeIgniter to the right function with data passed to the function for further processing.

Sample URL :

http://mysite.dev/verify/?id=emailaddress@gmail.com&hash=562828a975740ac6820e40f7f61b4407

Current Route :

$route['verify/(:any)'] = 'formcontroller/verification/$1';

Function :

public function verification($slug)
    {
        parse_str(parse_url($slug, PHP_URL_QUERY), $fileds);
        var_dump($fields);
    }

The problem is, I get a 404 when I try the url listed above. I get Message: Undefined variable: fields when I try something like http://amazon.dev/verify/asdasdasd

Can someone point me in the right direction?

ADD : If there is no ? in the url, it works. But for the standard of a get query url should be, I would like like to know how to solve this

Best Solution

Route doesn't receive query string as i understand. So, you should get variable from GET array. For this, 1st test that in config.php set

$config['allow_get_array'] = TRUE;

then in controller:

public function verification($slug)
    {
    $fields['id'] = $this->input->get('id');
    $fields['hash'] = $this->input->get('hash');
    var_dump($fields);
    }
Related Question