Home > php教程 > PHP开发 > Use JavaScriptHelper in Cakephp to introduce js files

Use JavaScriptHelper in Cakephp to introduce js files

高洛峰
Release: 2016-11-28 15:56:21
Original
1304 people have browsed it

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

Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template