30 June 2009

Add the jquery library to your php zend website

Today we are going to look at how to add the jquery library to your website in the Zend Framework.

Firstly you need to download the jquery library here.

At the time of this writing the current release is v1.3.2 and the size is about 55.9KB

Save/move that file to your 'js' folder, .e.g. c:\wamp\www\MyProject\public\js\jquery.1.3.2.min.js

Next step is to add it to your layout. Currently I'm adding my external javascript and stylesheet in my layout page. The common place for this view script is in /MyProject/application/layouts/script/layout.phtml, although I use /MyProject/application/views/layouts/layout.phtml. Whichever you prefer ;)

In the head section of layout.phtml I have this code:

headScript()->prependFile($this->baseUrl() . '/js/jquery-1.3.2.min.js'); ?>
headScript() ?>
I used prependFile instead of appendFile as this is the library and should be loaded first in my opinion.

Now if you save that and preview your page, the source should include something like this:

Now you have the jQuery library attached and ready to use it's commands and associated plugins. More on that in future articles.

Take care!
Tjorriemorrie

No comments:

Post a Comment