Process Widgets Javascript From Ajax Dynamic Content

I need some guides or basic advices and best practicies how to process widgets’ javascript code with my ajax content.

So, i have this structure:

Widget, lets call it CJavaScript extends CWidget which have Yii::app()->getClientScript()->registerScriptFile at init() method.

Statically loaded this widget works good, but i have 2 situations:

  1. CJuiTabs loading some controller action via built-in ajax

  2. I have my own function which load some controller action via ajax and then do $contanter.html(data);

widget obviously loads at this controller action and ofc doesn’t load javascript files

i also have 2 ideas:

  1. echo javascript right after widget which will lead to duplication if i cann this widget 2 times…

  2. awful code duplication where i stupidly load all possible widgets’ javascript files in a page and then load ajax for this code.

I want to read what is best practice to call those widgets’ javascript code if i load them via ajax, or this is bad idea overall, may be some advices?

The renderPartial() method is also used for Ajax calls, where the layout isn’t appropriate

<?php $this->renderPartial('//controller/view')?>


<?php $this->renderPartial('/controller/view')?>

and I think you should use a new JavaScript code in where your ajax is going to run.

yeah, i use renderPartial, but this doesnt helps at registering javascript code.

i think im going to make a static method init_js at widgets and then put all these calls to something like global method init_widgets_js