phpcodeignitergetisset

Does isset work with the CodeIgniter's get method?


Using CodeIgniter I'm trying to see if the 'ID' in the URL is 'uID' (user id) or 'sID' (system id).

The code I'm using is:

    if(isset($this->input->get('uID'))) {
        $getID = $this-input->get('uID');
    } else {
        $getID = $this->input->get('sID');
    }

When I use that I get a server error saying the website is temporarily down or under construction. Any ideas?


Solution

  • The warning you're getting is probably a 500 error -- meaning your server is not set up to display errors to you, or you don't have it enabled in your index.php file.

    The error you're getting, but not seeing is: "Fatal error: Can't use function return value in write context" because you can't use isset on a function.

    If you could it wouldn't do what you're expecting as CI's $this->input->get('key') always returns a value -- it returns false if the key does not exist.

    Therefore, to accomplish what it seems you're trying to do, you'd write:

    $getID = $this->input->get('uID') ? $this->input->get('uID') : $this->input->get('sID');
    

    Based on the comment below, I thought I'd also provide it in a way that makes sense to you:

    if($this->input->get('uID')) {
      $getID = $this->input->get('uID');
    }
    else {
      $getID = $this->input->get('sID'):
    }
    

    The two solutions are functionally the same.