0

i have passed argument in JS method and that methods argument needs to save in PHP Session but failed to do so ....... CODE:

 function checkBoxStatusUser1(condition)
       {

           console.log("condition checkBoxStatusUser1 :"+condition);
           setStatusDataUser(condition);
            <?php
        Yii::app()->session['var'] = condition;
       print_r(Yii::app()->session['var']); // Prints "value"
?>

       }

BUT THIS LOC: Yii::app()->session['var'] = condition; is not assigning condition's value either true or false to the session

Dairo
  • 822
  • 1
  • 9
  • 22
user3233280
  • 279
  • 2
  • 7
  • 21
  • 1
    you must have understand the different between client side execution(js) and server side execution(php) – Awlad Liton Mar 12 '14 at 06:11
  • possible duplicate of [Reference: Why does the PHP (or other server side) code in my Javascript not work?](http://stackoverflow.com/questions/13840429/reference-why-does-the-php-or-other-server-side-code-in-my-javascript-not-wor) – deceze Mar 12 '14 at 06:20

1 Answers1

1

Use Ajax for this. If you want to send a javascript variable from client side to server side, you should make an ajax call and send the variable in the 'data' property of the object parameter of the ajax call.

function checkBoxStatusUser1(condition) {
    console.log("condition checkBoxStatusUser1 :" + condition);
    setStatusDataUser(condition);
    $.ajax({
        url: '/requestHandler',
        data: {
            'condition': condition, //here you pass the data
        }
        type: 'post',
    });
}

And on server, make a script to handle request at '/requestHandler' and then do this-

 Yii::app()->session['var'] = $_POST['condition'];

You can get a decent understanding of it here -

http://www.w3schools.com/Ajax/

Tzar
  • 1,761
  • 2
  • 14
  • 21
halkujabra
  • 2,844
  • 3
  • 25
  • 35
  • can u please give me example – user3233280 Mar 12 '14 at 06:13
  • Glad it helped :) Upvoted :D I understand beginners are not entertained on stackoverflow. Even I face a lot of problems in beggining – halkujabra Mar 12 '14 at 07:20
  • can u help me i need to display checkbox in align = right after checkinng session variables value – user3233280 Mar 12 '14 at 07:27
  • $statusMaintain; session['var']) { // print_r(Yii::app()->session['var']); $statusMaintain = 'checked = "checked"'; echo '
    View All:
    ' ; } else { $statusMaintain = 'unchecked = "unchecked"'; echo '
    View All:
    ' ; } ?>
    – user3233280 Mar 12 '14 at 07:27
  • DOn't put code in comments,its really hard to read. Create a new question if its a different bug else update your question – halkujabra Mar 12 '14 at 08:36