Yii Framework Forum: String escape problem, please help! - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

String escape problem, please help! Rate Topic: -----

#1 User is offline   Ackley 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 02-May 14

Posted 07 October 2014 - 09:19 AM

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
0

#2 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 893
  • Joined: 19-February 13
  • Location:India

Posted 07 October 2014 - 10:37 AM

Please try this

"{$data["id_client"]}"

Thanks,
Ankit Modi
Skype : amodi06
0

#3 User is offline   Ackley 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 02-May 14

Posted 07 October 2014 - 11:17 AM

View PostAnkit Modi, on 07 October 2014 - 10:37 AM, said:

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 :(
0

#4 User is offline   skworden 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 174
  • Joined: 14-June 12
  • Location:Virginia, USA

Posted 08 October 2014 - 11:49 AM

Try something like this

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

0

#5 User is offline   Ackley 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 02-May 14

Posted 10 October 2014 - 10:25 AM

View Postskworden, on 08 October 2014 - 11:49 AM, said:

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 :(
0

#6 User is offline   Bizley 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 205
  • Joined: 29-July 14

Posted 10 October 2014 - 10:45 AM

Is there eval used on ['options']['click']? Try

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

0

#7 User is offline   georaldc 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 104
  • Joined: 08-July 11

Posted 10 October 2014 - 12:31 PM

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
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users