• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntax advice..

Evening folks -

What's a quick-and-dirty statement that does the same as the code below, without generating an object-error? I'm trying to find a shortcut that does not require assigning the function output to a variable and then testing the variable.


isset function does not require you use $this->input->post. try this:


Well that was my first guess Smile Seeing as If() evaluates a boolean true/false. For some reason it's giving me grief! Time to refactor..


[eluser]Dennis Rasmussen[/eluser]
Do you have a problem with the following?
If so, what? Smile

$this->input->post('id') will return false if the POST variable doesn't exist or isn't set, so there is no need to use isset (which anyway doesn't make much sense on the return value of a function as it will always be true).

you just need to be aware that the value 0 is also evaluated to false, so if the form value returns a value of 0 it will not process

The '0' value was my problem in this particular case... Smile

Thanks for the help!

Common PHP pitfall.

The only safe test is
if ( $this->input->post('field') === FALSE )
    // it does not exist

Heh! Funny that's what I ended up doing. Seems that typecasting the comparison gives you a clean yes/no.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.