2

I find very more posts about the problem, but all answers was unhelpful. For example Forcing Script Order from registerScript Method in Yii and yii CClientScript docs. Above posts had writen

registerScript(string $id, string $script, integer $position=NULL, array $htmlOptions=array ( ))

For getting above script:

<script type="text/javascript" id="some_id">
    console.log("sasasasas");
    //js code
</script>

I have piece of code:

$cs = Yii::app()->getClientScript();
$cs->registerScript(__CLASS__ . '#' . $this->id . 'Ex', '
        console.log("sasasasas");'
        //js code
   , CClientScript::POS_READY,  array('id="some_id"' ) 
);

But I could not get script like I expected. I got script without id="some_id".Could anybody can help me for find what I missed ?

EDIT
Does not work both versions:

$cs = Yii::app()->getClientScript();
$cs->registerScript(__CLASS__ . '#' . $this->id . 'Ex', '
        console.log("sasasasas");'
        //js code
   , CClientScript::POS_READY,  array('id'=> 'some_id' ) 
);

and

$cs = Yii::app()->getClientScript();
$cs->registerScript('some_id', '
        console.log("sasasasas");'
        //js code
   , ) 
);
Community
  • 1
  • 1
Ulug'bek
  • 2,762
  • 6
  • 31
  • 59

2 Answers2

2

I guess you have to change the line

array('id="some_id"')

to

array('id' => 'some_id')
chris---
  • 1,536
  • 1
  • 13
  • 14
1

May be someone will come across later with the problem. And I advice them, mustn't do my mistake. @Chris answer is right, registerScript() sets an id when you render view with render(), but when you use renderPartial() registerScript() does not set an id to script. You can find a solution from the post

Community
  • 1
  • 1
Ulug'bek
  • 2,762
  • 6
  • 31
  • 59