Using PHPQuery has an even bigger advantage if you are already using JQuery on the client side - after all why learn two different approaches.
You can download PHPQuery from:
where you will also find documentation and a community site.
Once you have the PHP library installed you can use it to generate the button example very simply:
$doc = phpQuery::newDocument();
The steps in the program are very simple. First we open a new document, then create a PHPQuery button object, complete with attribute settings, append the object to the DOM, and finally generate the HTML.
Of course there is more to PHPQuery than generating simple buttons and you can use it to process a DOM in complex ways in an efficient style that characterises JQuery. It even supports server side Ajax using a similar set of method calls!
The big problem is that PHPQuery also seems to have died as a project. You can still download the code but nothing seems to be happening any more - shame.
Generating HTML is PHP's main role in life and as such it is surprising that it does it so badly.
Quoting HTML tags is an easy way to get beginners started, but the horrible mix of HTML and PHP that results when you try to generate a real web page is far from good.
PHP needs an official, i.e. built-in to the language system, object-oriented way of generating HTML.
Until such time you will have to create your own solutions if you want to go down this road.
To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, Facebook, Google+ or Linkedin, or sign up for our weekly newsletter.
Metaclasses are an advanced topic and you generally don’t need to know about them or make use of them .....but knowing how they work might suggest alternative approaches to many problems. This extract is from my new book published on July 9th with the subtitle "Something Completely Different".
The Python decorator is one of its most powerful features and it is used to implement many of Python's own internals. It is a simple idea and yet it can be presented in a way that hides its simplicity. In this extract from Mike James' forthcoming book, we take a completely different look at decorators.
- << Prev