If does not compare Char

1

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

Follow 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 if($valor=='S') comparison is not being done, it is always returning false, but when I just return the passed parameter it returns the right value, which can be only S or N . / p>     

asked by anonymous 03.04.2017 / 02:34

2 answers

1

The function call was being made wrong, so the value was past, but it got some dirt in the memory, so he thought S was different from the past value. Here's how:

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

Thank you all.

    
03.04.2017 / 15:14
0

Give an isset in the various 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;
    
03.04.2017 / 03:10