I'm trying to use registerScript() to output some raw javascript into my page. The following seems to work fine (at the view level, called by a controller):
modules/myApp/views/readEditor.php:
<?php
$cs = Yii::app()->getClientScript();
$cs->registerScript(
'my-hello-world-1',
'var someCoolVariableInView = 11;',
CClientScript::POS_END
);
?>
This shows up before as it should:
/*<![CDATA[*/
var someCoolVariableInView = 11;
/*]]>*/
However, when I do the equivalent in a widget's view:
modules/myApp/components/views/myWidget.php:
<?php
$cs = Yii::app()->getClientScript();
$cs->registerScript(
'my-hello-world-2',
'var someCoolVariableInWidget = 10;',
CClientScript::POS_END
);
?>
The javascript does not show up.
I've done a bunch of googling but have not found anything helpful. My guess is the widget is filtering out the javascript...hopefully there's a parameter or config switch I can change to get this to output (or maybe there's a better way of doing this).
Thx,
Peter
UPDATE:
how widget is rendered:
<?php
class myWidget extends CWidget {
public function init() {
} // end init()
public function run() {
// ...
$this->render('myWidget');
} // end run()
}