如何在 CakePHP 2.0 中包含 JavaScript 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8384262/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to include a JavaScript file in CakePHP 2.0
提问by Alvaro
I am trying to include a .js file I created by using this:
我正在尝试包含我使用这个创建的 .js 文件:
echo $this->Html->script('vote');
My file is in /js/vote.js
我的文件在 /js/vote.js
I load the website and I go to the sourcecode, I click on the .js script file to see what it is loading and what I find out is that that the is an error loading vote.js
我加载网站并转到源代码,我单击 .js 脚本文件以查看它正在加载的内容,我发现加载 vote.js 时出错
When I try to access directly from the URL using:
当我尝试使用以下 URL 直接访问时:
http://localhost:8888/mysite/js/vote.js
http://localhost:8888/mysite/js/vote.js
I find this:
我发现这个:
Error: JsController could not be found.
Error: Create the class JsController below in file: app/Controller/JsController.php
<?php
class JsController extends AppController {
}
Then I created what it says, I get another error:
然后我创建了它所说的,我收到另一个错误:
Missing Method in JsController
Error: The action vote.js is not defined in controller JsController
Error: Create JsController::vote.js() in file: app/Controller/JsController.php.
<?php
class JsController extends AppController {
public function vote.js() {
}
}
What's the problem? Why is it so complicate to load a .JS file?
有什么问题?为什么加载 .JS 文件如此复杂?
I am just trying to make a button to vote on articles and I am driven crazy...
我只是想制作一个按钮来对文章进行投票,但我被逼疯了......
回答by Alec Smart
Have you created a file called "vote.js" in your app/webroot/js folder?
您是否在 app/webroot/js 文件夹中创建了一个名为“vote.js”的文件?
回答by mark
you include it correctly!
你正确地包括它!
my guess: mod_rewrite not on or some other wrong config setting
我的猜测:mod_rewrite 未打开或其他一些错误的配置设置