Can someone "translate" this in plain English to me, please? |
[eluser]developer10[/eluser]
Code: $update['id'] = (!empty($_POST['id'])) ? $this->input->post('id') : null; i suppose this line allows the id field to be null. however i need it never to be null. if i remove ": null", it throws the "unexpected ;" error
[eluser]Craig A Rodway[/eluser]
It uses the ternary operator to set the value of $update['id'] depending on the return value of testing if $_POST['id'] is empty or not. If $_POST['id'] is NOT empty, then $update['id'] is set to the POST'd ID; otherwise it is set to null. Think of it this way: Code: $result = (condition) ? IF_TRUE : IF_FALSE; If you want to remove it, just do this: Code: $update['id'] = $this->input->post('id'); However: Quote:The function returns FALSE (boolean) if the item you are attempting to retrieve does not exist. Input Class
[eluser]Blaze Boy[/eluser]
[quote author="cold_fusion" date="1262495063"] Code: $update['id'] = (!empty($_POST['id'])) ? $this->input->post('id') : null; i suppose this line allows the id field to be null. however i need it never to be null. if i remove ": null", it throws the "unexpected ;" error[/quote] this line will put $update['id'] with null if it's not sent with post ... the idea is to show error of it's not sent if( $this->input->post('id') ) $update['id'] = $this->input->post('id'); else show_error('error: id must be set');
[eluser]developer10[/eluser]
thanks, i'm about to elaborate on this, btw, i was trying to remember where in the user guide i saw this, but to no avail ![]() Thanks again!
[eluser]Colin Williams[/eluser]
Well, the CI user guide covers CodeIgniter, not the entirety of PHP. |
Welcome Guest, Not a member yet? Register Sign In |