Yii Framework Forum: Javascript in php page - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Javascript in php page bla bla bla.. Rate Topic: -----

#1 User is offline   pbklik 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 14-July 10

Posted 14 July 2010 - 10:12 PM

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>

Yii beginner programmer B)
0

#2 User is offline   megahertz 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 04-March 09
  • Location:Russia, Yekaterinburg

Posted 14 July 2010 - 10:25 PM

Use CClientScript.
0

#3 User is offline   pbklik 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 14-July 10

Posted 14 July 2010 - 10:31 PM

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 beginner programmer B)
0

#4 User is offline   mech7 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 220
  • Joined: 26-March 09

Posted 14 July 2010 - 11:42 PM

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

0

#5 User is offline   pbklik 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 14-July 10

Posted 15 July 2010 - 02:55 AM

View Postmech7, on 14 July 2010 - 11:42 PM, said:

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?
Yii beginner programmer B)
0

#6 User is offline   mech7 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 220
  • Joined: 26-March 09

Posted 15 July 2010 - 04:21 AM

As 3rd parameter use.. CClientScript::POS_READY
Then it will render the js in a jquery dom ready function :)
0

#7 User is offline   allankliu 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 09-July 10

Posted 15 July 2010 - 05:09 PM

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users