Posted on Sunday 30 October 2005
Peter Elst recently asked on osFlash if ARP had been translated to PHP. In truth, ARP, I believe, would not translate so well as a PHP framework because HTML and Flash are so different: HTML is stateless, involving a lot of text manipulation, while Flash is stateful, with lots of graphics manipulations. The view in particular is a very different concept in HTML and in Flash.
In any case there are already tons of frameworks for PHP. They vary from lightly abstracted to highly abstracted; some provide mostly organizational benefits, while others generate HTML, provide statefulness, data validation, template systems, kitchen sinks, etc. It seems pretty pointless to me to start a framework spec for PHP from scratch. There are already so much frameworks in every other language that we might as well adapt instead of reinventing the wheel, unless there really is something interesting to do that hasn't been implemented.
Fusebox for PHP is an adaptation of the popular ColdFusion framework that is very lightweight, providing a low level of abstraction and a good organizational framework. It work with 'fuses', which as I understand it are paths that are somewhat like AMFPHP's actions and filters.
Another popular solution is Cake, based on Ruby on Rails, which provides an organizational framework in addition to a database-record-to-class mapping scheme. Ruby on Rails has become a phenomenon all its own, with several books written on it, meaning you've got plenty of documentation to work with.
I like that the two above don't fall into the trap of abstracting everything beyond recognition. In particular they don't attempt to build a template system on top of PHP (ala Smarty), which is pretty stupid as PHP is a template system. I must admit however that despite it's use of a custom template engine I really like what I see with PRADO, which is definitely more on the 'kitchen sink' side of things. It defines it's own XML namespace on top of XHTML to create 'controls', in pretty much the same manner as ASP.NET. You can write for example:
<com:TButton Text="Login" onClick="onLoginClick" />
This will make the onLoginClick function be called whenever the button is clicked. This is certainly an interesting departure from the usual, boring old HTML way of doing things. It is described as 'component-based and event-driven'; combined with statefulness and data binding, you can see that this approaches the Flash/Flex metaphor. In fact, I wouldn't be surprised if you could define an mx namespace on top of it and... I'll let you use your imagination for this one ;)
I looked at several other frameworks (there at least 10-20 more) but none impressed me much compared to the previous... Until I saw this: QCodo. The homepage is boring enough, however it must be seen to be believed. Do yourself a favor and look at the 15 minute intro tutorial (in Flash, recorded with Camstasia, no less). This is amazing stuff. Basically it works as an event-oriented framework with a QuickForms-like component set. So far, nothing very exciting. However it comes with its own code generator, which really must be seen to be believed. It reads a table structure and from the types of each column it can generate pages for simple CRUD operations. It reads foreign keys and generates joins for combo boxes. It does data validation by itself based on NULL constraints and datatypes. This is just the generated code!!!
The code is object oriented and the framework generates both base classes which are continually overwritten by the generator and subclasses where you can override default behaviours. It has profiling and query logging built-in as well, as well as verbose errors when operations fail. Seriously, I was getting excited about doing a CRUD application after seeing this! I think that speaks volumes. Obviously it's not ideal for all application types but I can definitely see myself using this in the future.
Recently, Zend has announced that they will be developing their own framework for PHP. This is certainly good news and it's interesting to see PHP move towards patterns and MVC while keeping it simple and fast for low-complexity applications. The best of both worlds!


