Javascript in php page

Hi, i have a question about the javascript usability in yii,

let say i want to put some script inside my page like




$("#mydialog").dialog("open");



how can i insert the script by using yii framework without using


<script></script>

Use CClientScript.

how to convert this jquery script in yii?


$('#block-user-0').dialog(

		{ 	height: 'auto', width: 'auto',

			modal: true,

			show: 'clip',hide: 'clip',

			title: 'User Login',

			closeOnEscape: false,

			open:function() {

				$(this).parents(".ui-dialog:first").find(".ui-dialog-titlebar-close").remove();

				$(this).css('background-color','#ffffff')

			  }

		});

i try this, but failed at ‘open’ attribute:




$this->beginWidget('zii.widgets.jui.CJuiDialog', array(

'id'=>'mydialog',

'options'=>array(

    'title'=>'User Login',

    'autoOpen'=>true,'modal'=>true,

    'closeOnEscape'=> false,

    'show'=> 'clip','hide'=> 'clip',

    'open'=> array(

                     'function'=>

				'$(this).parents(".ui-dialog:first").find(".ui-dialog-titlebar-close").remove();

				$(this).css("background-color","#ffffff");'

			  ),

    ),

));

//echo 'Login Form';

$this->endWidget('zii.widgets.jui.CJuiDialog');




Yii::app()->clientScript->registerScript('dialog', '$("#mydialog").dialog("open");');

thanks mech7, btw i still cant get what i want from the following jquery code:


open:function() {

                                $(this).parents(".ui-dialog:first").find(".ui-dialog-titlebar-close").remove();

                                $(this).css('background-color','#ffffff')

                          }

and i try to put it in yii, but it doesn’t work:-


  'open'=> 'function(){$(this).parents(".ui-dialog:first").find(".ui-dialog-titlebar-close").remove();

			 $(this).css("background-color","#ffffff")}',

the code should open jquery dialog, with no ‘x’ button on the top right of the dialog

any suggestion?

As 3rd parameter use… CClientScript::POS_READY

Then it will render the js in a jquery dom ready function :)

Well, this is the first post I ever found in Yii forum, which is discussing about JS asset. I am totally confused about the asset management approach in Yii. I think the the simple JS/CSS asset is getting complicated since the front-end code have been mixed into backend PHP code. It is hard to maintenance.

I know sometimes the JS code should be generated on-the-fly by back-end. But in general, BE/FE code should be separated, especially in large scale projects.

The fact of discussing jQuery issue in Yii forum has proved my point.