tags:

views:

127

answers:

2

Hi all,

I've recently come across CakePhp as an excellent framework and am currently porting over my site to cake. In terms of using JQuery, what is the currently recommended method for including the javascript / accessing the javascript files. Doing a little digging, some people have suggested a central place in app/config ... what do you all think?

Thanks.

A: 

If you want jquery included on all of your pages, I would just put a line to include them in the section in the layouts used by your app. You can use the javascript helper, or just use standard HTML to include it with a tag.

Travis Leleu
+7  A: 

Add your javascript files including jquery to /app/webroot/js/.

Then on your layout (/app/views/layouts/default.ctp), just use the javascript helper to load your javascript files.

<head>
<title><?php echo $title_for_layout; ?></title>
<?php echo $javascript->link('jquery'); ?>
...
</head>

Make sure javascript helper is loaded on your app. Either on your app_controller.php or individual controllers.

var $helpers = array('Html', 'Form', 'Javascript');

jpdelatorre
Don't forget you can link jQuery from Google too!http://code.google.com/apis/ajaxlibs/documentation/index.html#jquery
DavidYell