0

I am new to CodeIgniter. I am trying to read values from query string in conventional method not segment.

This is my url.

http://localhost/Voyager/Main/UserActivation/?u=6df497644a10241cd89fad80f5c98496

Controller:

class Main extends CI_Controller{

     public function UserActivation()
    {
        $hash=$this->input->get('u', TRUE);
        log_message('debug', $hash, false); 
        $this->load->view('Main\view_userActivation');  
    }

}

I am trying to read value of 'u' in controller. But this isn't working. I am getting empty value in $hash variable.

Any help is appreciated.

3
  • Possible duplicate of Codeigniter get parameters from url Commented Apr 26, 2017 at 13:54
  • @DanWhite. If you check properly you will find that one which you mention talks about getting values from segment. Issue which I have mentioned is different. Before taking efforts to ask a question I have scanned more than 4 pages of google search results for issue. Commented Apr 26, 2017 at 13:55
  • Your Code should work. Just check you set $config['allow_get_array'] = TRUE; at your config.php andmake sure your url helper is loaded Commented Apr 26, 2017 at 17:17

4 Answers 4

2

Codeigniter works with URI Segments. You pass the values straight in your URL, separated with / and you grab them with positions after base_url like

$this->uri->segment(3)

Check this link: Codeigniter Documentation

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome. This is easiest answer I found for this. Thank you so much.
2

There's a config option that unsets the $_GET array, but only if you have decided to change it.
This is how it looks by default in application/config/config.php:

$config['allow_get_array'] = TRUE;

If you've changed it to false - switch it back to true. Other than that, there's no reason why this wouldn't work, by default.

Comments

1

you can do something like this

Method 01

class Main extends CI_Controller{

    public function UserActivation($u)
    {
        echo $u;
        die;
        $this->load->view('Main\view_userActivation');  
    }

}

Then URL should be

http://localhost/Voyager/Main/UserActivation/6df497644a10241cd89fad80f5c98496

Method 02

class Main extends CI_Controller{

    public function UserActivation()
    {
        $value = $this->uri->segment(3);
        echo $value;
        $this->load->view('Main\view_userActivation');  
    }

}

3 Comments

Thank you. Appreciate your effort. )
ha ha. No issues :)
Are you sure Method2 will work for the link that OP used?
0

Remove the / from the last uri segment.

http://localhost/Voyager/Main/UserActivation?u=6df497644a10241cd89fad80f5c98496

Also, another thing. Why you have your uri controller and methods starting in uppercase? That shouldn't be that way.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.