as I read from the book ‘jQuery in action’, it is important to seperate style, behavior and structure.
obviously, sytle can be placed in the
tag of the html file. and sytle is in the form of a CSS file to be linked into the html file.
in the head section of the html file.
Besides, yii put the head section of an html file in a layout(such as column2.php) shared by a lot of view files base on the value of Controller::layout. In this case, if we put all the script in the head section(
), it also shared by a lot of view fiels. but there must be some script is for some view files only.
So, would you please help me to seperate the script code and the HTML struct? Thanks a lot.
P.S.: Putting everything into separate files won’t automatically solve the problem of sharing variables between PHP and JS. To achieve that I use the HTML data atrribute to store arbitrary information that can be used by my scripts.
Yii does not put the js in the html, it uses the function
For register the needed script, which will be added in a script at the bottom of the page (you can configure it).
Anyway, Yii is a php framework with shome helper for js/ajax call, but is not a js framework.
If you are going to develop an application with strongly uses ajax, is better not to use the Yii helpers but to write the js code by yourself, using Yii::app()->clientScript->registerScript() for publish the needed scripts and snippets.