javascript - Where to put Js files in cakephp

775

I am wondering where to put my JS files so I don't make a complete mess out of my folders.

If I do a search on "Where to put Js files in cakephp" I get results of people explaining how to include a Js file into a page.

This JS file uses Ajax to post for example, books, to the database. So do I place this file in the controller folder, do I place it in Webroot/js/ under a certain folder or do I place it in the view folder?

724

Answer

Solution:

If you can't even answer that question for yourself, I highly recommend you to read the manual. If you already struggle with where to put the JS, you definitly will have trouble to figure out everything else as well.

The webroot directory is the public document root of your application. It contains all the files you want to be publically reachable.

JS goes to/webroot/js, images to/webroot/img and make your guess where the CSS goes to.

You should also read about the HtmlHelper to display files from the webroot.

But I personally would start here and do the tutorials.

340

Answer

Solution:

you should put your js file insidewebroot/js folder. and then you can simply include the js with the function in the view.

echo $this->Html->script('/js/fileupload/jquery.ui.widget.js');

People are also looking for solutions to the problem: php - Telegram API encode message to be sent

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.