If does not Char compare

Asked

Viewed 69 times

1

I created in codeigniter a helper for datatable that would return an html with a bootstrap icon.

Follows the function:

function trata_check($valor)
{
    $ci= & get_instance();

    if($valor=='S'){
                $html='<span class="glyphicon glyphicon-ok"></span>';
            }
            else{
                $html='<span class="glyphicon glyphicon-remove"></span>';
            }

    return $html;
}

The part that calls the function in the controller is this:

->edit_column('diario', trata_check('$1'),'diario')

The problem is that the comparison if($valor=='S') not being done, it is always returning false, but when I send only return the parameter passed it returns the right value, which can only be S or N.

  • The problem is how you are calling the helper, because what you are going through is the string '$1', not the value of the $1 variable.

  • To pass the value use double quotes, treat_check("$1")

  • Na can be the form that is passing the parameter inside the function? you are using simple quotes, therefore what will be passed would be the value $1 and not the variable value

  • The value is being passed yes, so much so that if I had it just return the value it returns normal, the problem is in the comparison. Anyway, I tried the suggestion and it wasn’t.

  • Where do you see the $1?

  • It is used to pass parameters in the edit_colum function of the CI.

Show 1 more comment

2 answers

1

The function call was being made wrong, the way the value was being passed, but it got some dirt in his memory, so he thought that S was different from the past value. Follow the correct way:

>edit_column('diario', '$1','trata_check(diario)')

Thank you all.

0

Give an isset on the variable sum, I think it will solve.

function trata_check($valor)
{
 $ci= & get_instance();

 if(isset($valor)=='S'){
  $html='<span class="glyphicon glyphicon-ok"></span>';
 }
 else{
  $html='<span class="glyphicon glyphicon-remove"></span>';
 }

 return $html;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.