Hello, don’t know if this is normal, but if I call renderPartial inside a view, when the processOutput is false the javascript is included anyway and if processOutput is true the javascript is included twice.
This is an example:
Controller
<?php
class SiteController extends Controller
{
public function actionIndex()
{
$this->render('index');
}
}
View demo.php
<?php
Yii::app()->getClientScript()->registerCoreScript( 'jquery.ui' );
echo CHtml::dropDownList('ddl', '', $data, array(
'class' => '123',
'ajax'=> array(
'type' => 'GET',
'dataType' => 'JSON',
'url' => '#',
'success' => 'js:function(){
alert("Ok");
}',
),
)
);
Yii::app()->getClientScript()->registerScript("js",'
alert("aaa");
',CClientScript::POS_END);
View index.php with processOutput false in renderPartial
<?php
$data = array(1 => 'a', 2 =>'b', 3=> 'c');
$this->renderPartial('demo', array('data' => $data), false, false);
this way the output include:
<script type="text/javascript" src="/demo/assets/3bf631ae/jui/js/jquery-ui.min.js"></script>
<script type="text/javascript">
alert("***********You should not see me***********");
/*<![CDATA[*/
jQuery(function($) {
jQuery('body').on('change','#ddl',function(){jQuery.ajax({'type':'GET','dataType':'JSON','url':'#','success':function(){
alert("Ok");
},'cache':false,'data':jQuery(this).parents("form").serialize()});return false;});
});
/*]]>*/
</script>
View index.php with processOutput true in renderPartial
<?php
$data = array(1 => 'a', 2 =>'b', 3=> 'c');
$this->renderPartial('demo', array('data' => $data), false, true);
this way the output include:
<script type="text/javascript" src="/demo/assets/3bf631ae/jui/js/jquery-ui.min.js"></script>
<script type="text/javascript">
alert("***********You should not see me twice***********");
/*<![CDATA[*/
jQuery('body').on('change','#ddl',function(){jQuery.ajax({'type':'GET','dataType':'JSON','url':'#','success':function(){
alert("Ok");
},'cache':false,'data':jQuery(this).parents("form").serialize()});return false;});
/*]]>*/
</script>
(( some html ))
<script type="text/javascript">
alert("***********You should not see me twice***********");
/*<![CDATA[*/
jQuery(function($) {
jQuery('body').on('change','#ddl',function(){jQuery.ajax({'type':'GET','dataType':'JSON','url':'#','success':function(){
alert("Ok");
},'cache':false,'data':jQuery(this).parents("form").serialize()});return false;});
});
/*]]>*/
</script>
[b]Operating system: Linux Mint 13 Maya 12.04.2 LTS, Precise Pangolin
Web server: Server version: Apache/2.2.22 (Ubuntu) Server built: Nov 8 2012 21:37:30
Yii version: Yii v1.1.13[/b]
BTW, Sorry for my bad English.