Welcome Guest, Not a member yet? Register   Sign In
passing parameter bug?
#1

[eluser]sukuiter[/eluser]
Hi, I just testing code igniter today. I found something weird.

In controller I got a value from variable then I pass it to the view.
Code:
if ($this->form_validation->run() == FALSE)
{
   echo "controller:".$this->input->post('level_up');
   $this->pass['level'] = $this->input->post('level_up');
   $this->load->view('form', $this->pass);
}


In the view I simply just echo the variable.
Code:
<?php echo "view:" . $level;?>

It's working for normal values, but what's not working is 0(zero). 00 is working.
The zero is printed in controller but not in view.

Is this a bug?
I'm using code igniter 2.0
#2

[eluser]InsiteFX[/eluser]
No it's not a bug! If the value is 0 it thinks it is FALSE so it will not print 0.
You can try this below, not tested!
Code:
$this->pass['level'] = ($this->input->post('level_up') == FALSE)
    ? '0';
    : $this->input->post('level_up');

You may also need to check it for NULL.

InsiteFX
#3

[eluser]sukuiter[/eluser]
[quote author="InsiteFX" date="1299785533"]No it's not a bug! If the value is 0 it thinks it is FALSE so it will not print 0.
You can try this below, not tested!
Code:
$this->pass['level'] = ($this->input->post('level_up') == FALSE)
    ? '0';
    : $this->input->post('level_up');

You may also need to check it for NULL.

InsiteFX[/quote]

I did several tests using isset() and empty() also.
The result is same. Seems like it's like you said, zero in php means empty or false.
I cannot use zero for status code then.. Sad

Thanks for the explanation Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB