The content of the head part of the page is mainly controlled by htmlhelper in Cakephp, while the js part is controlled by JavaScripthelper. Set it in the controller: var $helpers = array('Html','Javascript' ); You can use the JavaScript helper object: $javascript in the ctp file. See text for details.
The premise is that the js files are placed under the webroot/js directory. The following is an example.
1. $javascript->link($JsName,0); echo $script_for_layout;
In the views/controllers/method name.ctp file, use $javascript->link($JsName,0); The webroot/js/jsname.js file is loaded into $script_for_layout of views/layouts/default.ctp.
2. echo $javascript->link($JsName,1);
This sentence is used directly in views/layouts/default.ctp, just put it in the head area, or place it in views/controllers /Method name.ctp file is also possible.
3. echo $javascript->includeScript();
This statement is very awesome. It directly reads all webroot/js/all js files and prints them out. It feels the same as PHP's include function. Other statements generate . This generates the content of