String escape problem, please help!

Dear all,

I try to use an extension called DzRaty for Star Rating on CGridView which worked fine for me. However, I have a problem with escape string that took several hours but I still couldn’t solve it. My problem is like this:




                array(

                    'name' => 'score',

                    'class' => 'ext.DzRaty.DzRatyDataColumn',

                    'value'=>'$data->score',

                    'options' => array(                                    

                        'readOnly' => FALSE,

                        'space' => FALSE,

                        'path' => Yii::app()->request->baseUrl. '/img' ,

                        'click' => "js:function(score, evt){

                            $.ajax({

                                type: \"POST\",

                                url: \"http://localhost/client/update\",

                                data: \"id=$data->id_client&score=\" + score,

                                success: function(msg){

                                    alert(\"Thank you for your feedback!\")

                                },

                                error: function(xhr){

                                    alert(\"failure\"+xhr.readyState+this.url)

                                }                        

                            })

                        }",                       

                    ),

            	),




The issue come at the line


data: \"id=$data->id_client&score=\" + score,

as PHP compiler complaining about Undefined variable: data . If I change


$data->id_client

to 1 or any valid client PK it works. Could anyone please kindly help? Thank you in advance!

Ackley

Please try this


"{$data["id_client"]}"

Thank you, I have tried but unfortunately that doesn’t work. As long as that $data is keyword highlighted in an IDE, I will have that complain. For example, in


'value'=>'$data->score'

,


$data->score

is not highlighed in IDE then that is fine, as soon as I remove the single quote then I have the same error. I don’t know how to do string escape so that


$data->id_client

in my above code is treated as a string :(

Try something like this


'data'=>'js:$(this).serialize()+"id='.$data->id_client.'"+score',

Thanks for your help but $data is still not recognised (PHP undefined warning) because it wasn’t escaped :(

Is there eval used on [‘options’][‘click’]? Try


data: \"id=" . $data->id_client . "&score=\" + score,

Don’t know about using that specific extension as a cgridview column value but I think you should be able to access the current cell inside your click event (like $(this).text() if it were just a normal text entry)

EDIT:

Sorry, didn’t notice you wanted another value from your model. I think the only way to do that is to search your grid’s dom for the value if it exists, starting from your click event’s element. I don’t think there’s any easy way to pass your $data variable to that javascript function