clientScript register

I use this to register scripts but only part of it works




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

Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl.'/assets/js/jquery.pngFix.js');

Yii::app()->clientScript->registerScript('logoFix','$(function(){$("a.logo").pngFix();});');



only jquery and jquery.pngFix are rendered, the third line doesn’t have any effect.

I figured i’m doing something wrong but since i cant find any examples with what i want to do, i am asking someone who knows how to use clientScript->registerScript to help me with this. thank you in advance.

You don’t need the $(function() { … }) in you registerScript call.

By default, this method uses the CClientScript::POS_READY option, inserting the javascript code inside $(document).ready() function.

So, you need only:


Yii::app()->clientScript->registerScript('logoFix','$("a.logo").pngFix();');

even like this


Yii::app()->clientScript->registerScript('logo','$("a.logo").pngFix();');

nothing is displayed. did i do something else wrong?

Everything works fine here. What you mean by "nothing is displayed"? The PNGFix is not working? The script is not rendered in your html output? By default, the code is inserted in the end of your document. Before the <body> closing tag, you should have something like:




...

<script type="text/javascript"> 

/*<![CDATA[*/

jQuery(document).ready(function() {

$("a.logo").pngFix();

});

/*]]>*/

</script> 

</body>

...



Where are you calling this methods?

lol please forgive my ignorance, when viewing the rendered source i was checking for the code in the head and didn’t scroll to the end of the source, it works, no wi just have to work on getting the png fix to work like i want it to.