Jquery In Yii

hi im newb to this framework and i have done some sample codes and when i started to add jquery in my samples i dono how to do it. is there any a link or reference or good tutorial for jquery in yii framework i have seen most links they all just about definiton oly and they are good.

. pls post some links and tuts for it . thanks in advance

Hi,

this code for subscribe/unsubscribe link

and you must have to include jqury css and js file in your view file




<p>Click to 

                    <a class="link" onclick="subscribe(<?php echo $subscribe->id; ?>);"><span id="subtext">

                    <?php if(isset($subscribe->newsletter_subscribe) && $subscribe->newsletter_subscribe==1)

                            { 

                                echo "unsubscribe";

                            } else {

                               echo "subscribe"; }

                    ?>

                        </span>

                    </a>

                    monthly newsletter

                </p>






<script>

    function subscribe(id)

    {

        subs = $("#subs").val();

        

         $.ajax(

             { type: "POST",

                url: "<?php echo Controller::createUrl('home/subscribe');?>",

                data:"id="+id+"&subs="+subs,

                success: function(data)

                {

                    $('#subs').val(data);

                    if(data==0)

                    {

                        $('#subtext').text("subscribe");

                        msg = "subscribe";

                    }else{

                        $('#subtext').text("unsubscribe");

                        msg = "unsubscribe";

                    }

                    $('#msg').html('<div class=\"flash-success\">'+msg+'</div>').fadeIn();

                    setTimeout( 'jQuery(\'#msg\').fadeOut();',3000 );

                }

         });

    }

</script>



Google can help you.

I’'l try to give you my help. First of all, type this code to add jquery to your web pages:


Yii::app()->getClientScript()->registerCoreScript('jquery');

Then, type this to add your own script:


Yii::app()->clientScript->registerScriptFile(

    Yii::app()->baseUrl.'/js/file.js'

);

or if you are using themes:


Yii::app()->clientScript->registerScriptFile(

    Yii::app()->theme->baseUrl.'/js/file.js'

);

Finally, you can work on your jquery file:


$(function(){

    // ...

});

Try to keep separate javascript and php.

thanks that was really helpful. i tried the basic and it worked out thank you