shgpan
(Philippe Pan)
September 24, 2011, 12:05pm
1
hi ?
i presume every one would have to add some of your own js or Jquery code to add some special feature to your pages. but what’s the best way to add them.
i know wonderful Yii has provided us an interesting CClientScript component,but what’s the right way to use it.
look what i do:
<?php
$JQuery_User='
$("blablabla").bla(){
blablablabla;
blablablabla;
};
$("klaklakla").kla(){
klaklakla;
};
';
Yii::app()->getClientScript()->registerSCript('JQuery_User',$JQuery_User,CClientScript::POS_END);
?>
is there a better way?
thanks!
dckurushin
(Diavolonok)
September 24, 2011, 12:08pm
2
more elegant would be creating a .js file
shgpan
(Philippe Pan)
September 24, 2011, 12:15pm
3
but what if you have to pass variables to JQuery or js? like this:
<?php
$JQuery_User='
$("blablabla").bla(){
blablablabla;
blablablabla;
var data='user='.$userName; //passing php variable to jquery.
bla(){};
};
$("klaklakla").kla(){
klaklakla;
};
';
then you will have to do this way, no other possibilities, am i right?
dckurushin
(Diavolonok)
September 24, 2011, 12:44pm
4
Generally passing variable can be done like you wrote, but if this only username, you can also use cookie
sensorario
(Sensorario)
September 25, 2011, 1:06pm
5
I’d wrote this wiki few days ago. I hope it can help you :-\