Thursday, February 22nd, 2007

PQuery – PHP and jQuery

Category: jQuery, Library, PHP

<>p>PQuery is to jQuery as Rails helpers is to Prototype and

PQuery is a set of helper classes for JQuery JavaScript library.This library allows you to easily integrate AJAX , Effects and other JQuery functionality into your PHP scripts.IT has a small foot print and is compatible with PHP4 and PHP5.

  1. < ?=$pquery->form_remote_tag(array('url'=>'index.php?task=ajax','update'=>'#idtoupdate'));?>
  2. Field : <input type="text" name="field" /><br />
  3. <input type="submit" />

Posted by Dion Almaer at 6:23 am

3.8 rating from 219 votes


Comments feed TrackBack URI

dudes, I almost started writing this. THANK YOU! I’m jumping on the dev band wagon. Is there an irc channel? svn trunk? What’s going on here?

Comment by Phillip Jacobs — February 22, 2007

i think it makes things neither simpler nor clearer nor neat. it may be only helpful if you have to code qucik “do and forget” code, not mentioning it’s useless if you care about unobtrusive js. put your js where it belongs, in external file.

Comment by sopel — February 22, 2007

This is an awful idea.

The beauty of jQuery is that it allows you to easy implement Hijax, storing all behaviours externally to the semantic markup. pQuery destroys this ideal by sticking a load of onclick attributes within the document. Wrong wrong wrong.

Comment by Stephen Reid — February 22, 2007

Ha, we posted that at the same time!

Comment by Stephen Reid — February 22, 2007

It’s rubbish. Period. Stephen explained why already. And yet, a million idiots will use it and praise the idiot developers. You don’t need helpers to generate javascript. Or form tags. Or image tags. End of story.

Comment by David — February 22, 2007


You’re killing kittens with that code! At least, if you *need* helpers (and some people just need help) why not go for something better and replicate the UJ4Rails plugin as that at least will put all the JS in one place.

Comment by Ross — February 22, 2007

What, filling page with inline javascript and onclick’s? I hope nobody will really consider this help.

Comment by digitarald — February 22, 2007

@everone: Guys, before bombarding the author of pQuery with negative comments, I’d like to suggest that you offer up some true “constructive criticsm”. Remember that one of the things that we strive for on the jQuery project is to offer a positive community experience. That includes offerring suggestions that will help developers build better applications, plugins or, in this case, frameworks. I’m certainly not saying to accept or like his work but I would ask that you tone down the replies and provide a thoughful explanation of why this may or may not work. Does that make sense? :o)

A link to his blog post can be found here:

jQuery Project Team

Comment by Rey Bango — February 22, 2007

Constructive criticism: flush it down the toilet. These “helpers” are the worst plague the web has ever seen and I dare to say they are just as much of a danger to this planet as global warming. This stuff is wrong and useless and harmful by any stretch of the imagination.

Comment by David — February 22, 2007

I second Rey Bango.

Comment by jd — February 22, 2007

helpers are good for those of us that are more familiar to php than javascript. but it should have a logic of storing all generated javascript on an external file. which would create quite an unmaintainable mess. Personally i prefer to keep things a little bit less automated and have an understandable file organisation. I’m not saying it is impossible with helpers, i just haven’t seen it done yet.

Comment by Alexandre Plennevaux — February 22, 2007

This isn’t the end all be all of helpers. Although it’s a great start (0.1 release COME ON!!). Don’t bash helpers if you don’t need them, just understand why they exist. If I’m a developer that mainly writes business logic, and work for a company that from one day to the next expects web2.0 javascript doodles without any man power incr, or anything, a helper library in the language I’m used to. In the enviornment I’m comfortable with, is a great help.

Comment by Phillip Jacobs — February 22, 2007

Theres nothing wrong with helpers but you need to not draw the line between helping use jquery and auto mangling html. I don’t want a php library trying to force me to use its generated form tags and such.

My page should be able to be a simple non-dynamic html page if I want that calls php through jquery.

My demo of something to this sort

Its not pretty it is a old proof of concept pre jquery 1.1.1

Comment by Richard Thomas — February 22, 2007

@jd: Thx man! :o)

Comment by Rey Bango — February 22, 2007

@David: I respect your opinion my man. How about explaining why helpers are a problem? It would to quantify your statement so that it sounds reasonable. From the subsequent replies, its seems that some actually like helpers and you might be able to help them understand some sticking points.

Comment by Rey Bango — February 22, 2007

Hey ,
i just checked this out today,and i think i have a more scalable version of this ,which i call tvHTMLHelper .check it out here . Ive even commented on a few pitfalls in pQuery which ive taken care of .

Even hacked up a small Tag Creator using my library ,after seeing this post .

Keep Clicking,
Bhasker V Kode

Comment by Bhasker V Kode — February 22, 2007

Here’s the link

Comment by Bhasker V Kode — February 22, 2007

Some pretty harsh replies in here , looks like some people don’t like the whole concept of helpers, PQuery and “Global Warming” man what comparisons. Well for all those who feel that this shouldn’t be done , there is a group who is thankful and will use it (including me).

I never intended to mess things up,my intentions were to get things done faster,easier and in a language im good at ( PHP in case of web dev ) and a JS library which i liked. I could have wrote each and every event handler,effect,Ajax request in a separate file but i work with custom CMS’s and frameworks most of the GUI/HTML is auto generated from Databases and XML, so i like everything in one place. I have other reasons too … but i think they’ll spark more debates so ill refrain.

Im not forcing you to use them ,so rather than criticizing it and wasting your time, do something constructive.

Comment by Vikas — February 23, 2007

you should propose it to cakephp !

Comment by wluigi — February 23, 2007

Using PHP to generate Javascirp code? What for? Is that clear and nice?
In my opinion not! What wheen user doesn’t accept javascript? The page are broken.
Ajax yes, but not from PHP code. That’s toad going to nothing. The dynamic elements should be added by browser from behaviour.

Comment by splatch — February 23, 2007

While I may not find this all too useful, I don’t think it’s necessary to degrade this coder. Why spit on his work? It doesn’t help him. A previous response stated to try to make more constructive criticism. Here’s mine:

Take in the positive parts of the previous posters. They have some insite on what they’re talking about. They may come off as stupid with the manner they present themselves but just ignore that and be the better person.

Comment by soldier — February 28, 2007

Part of developing applications for the web is learning how to separate your interface from your functionality. This implementation clearly tries to combine the two which is completely against this fundamental law.

Another note, jQuery is an implementation layer based on Javascript, not a replacement for writing HTML code. Ditch this concept and learn to write Javascript separately, it can only help you in the long run.

Comment by Craig — July 26, 2007

Quote: “you wouldnt use PHP for formatting HTML and using loops to build tables.”

That is correct, I would not use PHP for formatting HTML. I would use an interface language such as Javascript or CSS. I do not generate HTML using PHP, I generate variables and make substitutions into HTML templates using PHP. I pass back XML or JSON data from AJAX calls and use Javascript and CSS to re-apply the data to an HTML page.

When your application gets larger, try to find all of your embedded HTML within your PHP code when you need to make an interface change. Sounds counter-intuitive to me. Why should you modify PHP to change your interface?? What if you want the same code to now produce XML instead of HTML?? Or even, just generate pre-formatted text.

This solution works well for a “one-man-shop” but not for a multi-developer environment with each developer at a different skill level. Use it as you feel necessary but understand the long-term implications before doing so. To each their own but I for sure do not support this idea.

Comment by Craig — August 8, 2007

I came to this page hoping to see a utility that let me parse an HTML document using CSS selectors server side in PHP.

What do you think about that idea instead?

It would make for nice screen scraping and maybe even for manipulating DOM on the server (to return a new HTML result to the client).

Comment by Zach Leatherman — February 28, 2008

for all the negative comment authors on this thread. Have you guys/gals ever played around with JSF’s IceFaces or RichFaces? Seems like the java community has something to offer the PHP community when it comes to integrating js with code. This project looks good and reminds me a bit of that.

Dont knock this idea just because its a new idea or threatens your 3lit3 js status. It has great potential and to be honest Javascript is a mess to deal with in a large scale environment even when you follow the guide lines.

My 2 cents and looking forward to another release.

Comment by armandopadilla — June 20, 2008

I’ll agree that it’s sloppy to use JavaScript code inline with HTML…this is something that we all did at one point in time and [most of us] eventually got out of the habit. I suppose it has its uses in some applications, but I prefer not to whenever possible. External JS files are the way to go for clarity, cleanliness, and code recycling.

I also agree that generating JavaScript code with PHP is not the best idea. In many case I found that it was easier to send a variable from PHP to JS that way, but with a little more effort you can to do it the “right” way, so there really isn’t any point in ever doing this, in my opinion.

I think a more useful solution for a helper would be an app that generates your HTML, JavaScript, and PHP in separate, readable files. This way you could create simple, yet functional foundations using the automated tools and build on them as needed. Seems to me it would be the best solution that would satisfy both the amateur and expert developers, and still be easily maintainable.

Comment by aksival — June 27, 2008

Leave a comment

You must be logged in to post a comment.