Alvaro
Alvaro

Reputation: 41605

How to include a JavaScript file in CakePHP 2.0

I am trying to include a .js file I created by using this:

echo $this->Html->script('vote');

My file is in /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

When I try to access directly from the URL using:

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?

I am just trying to make a button to vote on articles and I am driven crazy...

Upvotes: 1

Views: 26074

Answers (2)

mark
mark

Reputation: 21743

you include it correctly!

my guess: mod_rewrite not on or some other wrong config setting

Upvotes: 0

Alec Smart
Alec Smart

Reputation: 95980

Have you created a file called "vote.js" in your app/webroot/js folder?

Upvotes: 5

Related Questions