views:

558

answers:

7

Hello,

I've been writing PHP web applications for some time, and have come across very nice Javascript frameworks, such as JQuery, ExtJS, Scriptaculous, etc. I can't say the same about the PHP side - I always coded that part of the client-server dialog from scratch.

I've used CodeIgniter (http://codeigniter.com/) and it is nice, but doesn't deal with AJAX as a whole - rather providing input checking, image manipulation, and some output helpers.

Is there a standard PHP library/class/framework out there that deals/integrates with Javascript frameworks? Something that can catch users' responses/requests, validate identity and input, provide progress status, keep track of sessions, be aware of asynchronous events, etc.

+4  A: 

There might be one but I can't imagine why. An AJAX request looks and acts just like an HTTP request from the perspective of the server. You can get and set cookies. All the environment variables that you would expect from an HTTP request are there. All of the HTTP verbs work as do any of the header fields.

Glenn
With the exception that you rarely want to return a full HTML response.
noah
Also, AJAX requests are sent for every purpose under the sun--whereas a HTTP get/post is just to retrieve a HTML page by and large. (Not that they can't be used otherwise.)
The Wicked Flea
AJAX uses HTTP so it is not true that HTTP get/post is just to retrieve an HTML page. YOu know how you put all these HTML tags in your PHP file? Well, you don't have to do that. Even though the acronym says Hypertext Preprocessor, you can use PHP to generate any kind of text include JSON or XML.
Glenn
+9  A: 

The Zend Framework is integrated with Dojo Toolkit. I haven't used the latest Zend Framework yet, but I do know that in the past, it has proven to be reliable.

Thomas Owens
I was going to suggest this - so rather I'll just upvote you :-)
leek
Agree... and while I haven't used the Dojo integration yet, my colleague has and seems to like it for the most part.
Michael Johnson
+1  A: 

The only difference in what I do when I'm returning JavaScript or HTML to a browser for AJAX is to not output the headers or any extra data. (The error handling I use outputs errors when in debug, so I have disable this as well.)

Darryl Hein
+3  A: 

In the next major release 1.5 CakePHP will come with jQuery.

powtac
+2  A: 

Sajax is one of a number of libraries that provide an easy way to link callbacks from client-side (JS) to server-side (PHP). Another library which does something similar is JPSpan however I am not sure if it is still actively supported. I have only done minor experiments with these two libraries so your mileage may vary.

wioota
+2  A: 

Using a library is fine as a convenience once you understand the concept, and you probably do, but for others reading this I suggest doing it by hand a few time first and really understanding it. I also recommend the book Bulletproof AJAX. It's fairly short, well written and describes not only how to use AJAX, using PHP as a programming language, but also how to create pages which take advantage of AJAX but still work OK if the user has JavaScript turned off.

Devin Ceartas
A: 

Yes, PHP can output XML and JSON for Ajax but not all PHP frameworks support JSON/XML equally well.

For example: I ran into an problem in Drupal (4.7) where the PHP sessions would be deleted after outputting a JSON response. (The HTML output code was explicitly closing the session, which was required or the session would be erased.)

I would also love know about PHP frameworks that make it easier to manage to javascript code. Even something basic such as including jQuery only on the pages that require it. Or helping to manage minimizing/packing javascript code.

Jason Moore