Archive

Posts Tagged ‘cakephp javascript’

Javascript in CakePHP 1.3

July 8th, 2010

The newly updated version of CakePHP in version 1.3 packs a punch! It is now more easier to code as the Helper methods are better organized now.

For instance, linking external javascript in CakePHP 1.2 is quite an hassle as Javascript itself has Javascript Helper. However, The Javascript Helper is deprecated in 1.3 and will be removed in future versions of CakePHP. Henceforth, lets look at how HTML Helper load javascript.

In CakePHP 1.2, to load an external javascript, we do this:

<?php echo $javascript->link("jquery", true); ?>

Now in CakePHP 1.3, we can make use of HTML Helper, we do the following:

<?php echo $html->script("jquery"); ?>

Nevertheless, if you have multiple external js file to load, you can load it into an array:

<?php echo $html->script(array('jquery','wysiwyg','scripts')); ?>

Easy and more organized now eh? External CSS files were all along being load using HTML Helper. Now with the loading of Js files through HTML helper instead of invoking Javascript Helper, it is much more convenient! Moreover, you will only need to load one helper which is HTML Helper instead of loading 2. :D

Willie Programming , , ,