Saturday, January 29, 2011

Re: Jquery Help

First, you'll want to include the jQuery library in the head of your
page. I do it on my default layout using the following code:
/app/views/layouts/default.ctp
echo $html->script('https://ajax.googleapis.com/ajax/libs/jquery/1.4/
jquery.min.js');

This is hosted via google but of course, you can always link to a copy
that you download and save in the /app/webroot/js/ folder:
echo $html->script( 'jquery.min' );

For the page-specific jquery code, I usually save common code together
in a file and save it in the /app/webroot/js/ folder and link to it in
whichever view needs it:
/app/views/controller/your_view.ctp
echo $html->css('jquery_file', null, array('inline'=>false));

By specifying inline=>false, it forces the script to be output in the
$scripts_for_layout variable in my default layout.

To use jQuery, you can simply call selectors as you would with any
HTML document. Submitting form data to the controller via ajax might
look like this:
/app/webroot/js/jquery_file.js
$(document).ready(function(){
$('#YourButtonID').click(function(){
$('#YourFormId').submit();
});
});

I'm most comfortable creating my own jQuery, so the example above
isn't very cake-esque. You should look into the JsHelper to work
within Cake's guidelines. If you do that, remember to include the
following code right before you close the body tag:
/app/views/layouts/default.ctp
echo $this->Js->writeBuffer();

This outputs all the javascript that you create in your views, etc.

Good luck.

On Jan 29, 9:40 pm, tubiz <tayi...@gmail.com> wrote:
> Please as many web designers will say Jquery is one of the most
> popular Javascript framwework. But the problem i am having is how to
> implement jquery in my cake apps.
> Is is in the view i will import the jquery source and how do i write
> custom jquery code to target specific section of my site like a form
> ("that will be created using the Form Helper") and is it possible to
> use to jquery autocomplete plugin on my site.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: