Frage

I know this kinda seems like a stupid question and with more research i might be able to find the answer but i have a deadline to please help.

Using codeigniter im trying to see if the 'ID' in the url is 'uID' (user id) or 'sID' (system id).

the code im 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 website is temporarily down or under constrcution. Any ideas?

Thanks in advance for the help. Usually i would spend more time searching for the answer myself but i just dont have time tonight.

War es hilfreich?

Lösung

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.

Andere Tipps

isset works only on variables.
$this->input->get() is a function call. That gives you an error.

I would guess that if uID isn't set in the request, $this->input->get will return null or false or some such. I.e. you don't need isset, the return value should already be falsey.

I'd recommend you invest the little time it takes to read The Definitive Guide To PHP's isset And empty.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top