[英]How to include a JavaScript file in CakePHP 2.0
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脚本文件以查看它正在加载什么,我发现加载票证是一个错误。
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... 我只是想按一下按钮即可对文章进行投票,我被逼疯了。
您是否在app / webroot / js文件夹中创建了一个名为“ vote.js”的文件?
you include it correctly! 您正确地包含了它!
my guess: mod_rewrite not on or some other wrong config setting 我的猜测:未启用mod_rewrite或其他错误的配置设置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.