1

How would I import an entire JS library, with associated CSS and IMG files into CakePHP?

I'm trying to get jQuery.Gantt Chart into my project.

I've tried splitting it up into the three folders to conform with Cake's structure but there are so many js files and references that need to be fixed - I can't get the tool to work once I meddle around with it. Is there an easier way to import this into CakePHP?

1 Answer 1

2

Put it in a folder in your webroot.

Example:

/webroot/jquery-gantt/

Then, when you call it's js (or css), just make sure to start with a /.

echo $this->Html->script('/jquery-ganett/whatever.js');

There are many cases where it just doesn't make sense to break apart groups of files like that and is not a big deal to just keep them together.

Sign up to request clarification or add additional context in comments.

5 Comments

Hi Dave, I tried this but it won't work.. I have this in my header: echo $this->Html->script('/js_plugins/gantt.chart/js/jquery.fn.gantt.min.js'); but when I view the source on Chrome, it's pointing to http://localhost/project02/js_plugins/gantt.chart/js/ which when visited throws a missing controller error.
@Chronix3 - Then there's something wrong w/ your CakePHP setup and is unrelated to this specific question. (or the file you're pointing to doesn't actually exist). What you're asking is something I do on a 3-4 times a day basis, and my answer IS correct.
@Chronix3 - Make sure modrewrite is on?
This is driving me insane.. :( <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_URI} !^/js_plugins/(.*) RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L] </IfModule> That's my .htaccess, trying to exclude the js_plugins folder but its not working.
Oh wow, silly me. When I read webroot I took it literally as the root of my project and not the folder in the CakePHP structure... It all works well now! Thanks Dave :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.