11 April 2011
Adobe Flash Builder for PHP, a recently introduced version of Flash Builder 4.5 co-developed by Adobe and Zend Technologies, could be one of the more interesting cross-platform integrations in a long time.
Back in the yesteryear of 2008 AMF support was added to Zend Framework for PHP. AMF stands for Action Message Framework and it is the de facto standard for communicating with Flex applications. What makes this interesting is that while there are lots of mechanisms for connecting between two different languages, this integration couples the Adobe Flash Platform and PHP—two of the most popular ecosystems for web-based applications. They operate almost exclusively at opposite ends of the spectrum and came to their popularity through very different paths.
The Flash Platform’s popularity came through the strong support of a company that built its reputation on providing tools to create engaging UI experiences, whereas PHP became popular because it democratized server-side application development. In other words, PHP brought web application development to the masses.
The addition of Zend_Amf to Zend Framework provided the integration point for Flex applications, but the tooling to make that easy was missing. Flash Builder 4 included an interface to PHP that used Zend Framework, but the level of integration in Flash Builder for PHP makes connecting to PHP services even easier.
With Flash Builder for PHP great steps have been made to reduce some of the barriers that were present earlier. Adobe and Zend looked at the workflow that both PHP developers and Flex/ActionScript developers use to build their applications and worked hard to streamline that process. The goal is to provide you with as much freedom as possible while providing a foundation strong enough to keep you from shooting yourself in the foot.
This article includes a high-level look at several new features in Flash Builder for PHP. After covering the basics of creating an integrated project, it explains the new introspection tools and continues on to debugging. Once you’ve completed this article, you should be able to start working quite easily—either starting an application from scratch or providing a rich UI to your existing PHP application.
Flash Builder for PHP is an integration of the Adobe Flash Builder product and the Zend Studio product, both of which are recognized as leaders in their respective spaces. There is always interest in marrying a great UI with great data, so bringing these two products together to help developers build compelling Flex and PHP applications is a natural fit.
To set up a great environment for building Flex and PHP applications, use Flash Builder for PHP as your IDE and Zend Server for the back end. Zend Server is the Zend PHP application server and is available in both free and professional editions. For the purposes of this introduction, you’ll only be using the installed debugger, so if you are not already using Zend Server, then installing the free Community Edition version will be sufficient. If you are using your own PHP server you will need to download the Zend Debugger, as it is required to work with some of the tooling provided in Flash Builder for PHP.
Zend Framework is added by Flash Builder to the PHP include path for any PHP project that you intend to use as a data service, even if it’s not a Zend Framework project per se. This is because Flash Builder for PHP connects to your PHP application using a component in Zend Framework called Zend_Amf. You may not need to use any of the other features, such as MVC or database access, but you will need to have the Zend_Amf component available for the gateway in order to communicate with your Flex application. If you are using Zend Server, it is probably already installed for you.
Flash Builder for PHP introduces much tighter integration between Flex and PHP projects. Although it was possible to connect to PHP services from within Flash Builder 4 due to the inclusion of Zend Framework, now the relationship is much stronger. You’ll see that in action a little later on, but first you need to set up your workspace environment.
There are two mechanisms you can use to integrate Flex and PHP projects, which I have dubbed Fraternal projects (non-identical twins) and Sibling projects (same parents, but with more pronounced differences). This is not official terminology, but it helps to differentiate the two mechanisms.
When I refer to a PHP project, it can either be a plain PHP project or a Zend Framework project.
To create a Fraternal project, you simply choose File > New > Flex and PHP Project or File > New > Flex Mobile and PHP Project (see Figure 1) and use the wizards.
This method is the easiest to use and it works best when running on a default installation. In other words, if you are starting out from scratch with a new installation of Zend Server and Flash Builder for PHP, this will probably be the way to go.
Both Flex and Flex Mobile projects can connect to service layers that have been made available via PHP. Indeed, they can even share a PHP project if you have both a Flex and a Flex mobile project that access the same PHP data sources.
If you find you need to switch between PHP projects in your Flex application or if you have an existing PHP application that you would like to expose to a Flex interface, Sibling projects are likely the better option. It is actually quite easy to associate an existing PHP project with the Flex project:
You may still need some minor configuration changes, but using this mechanism will get you up and running easily with an existing PHP project.
With the original Flash Builder 4 PHP integration there were a few constraints that you needed to work around to create access points to remote PHP projects. The most obvious was that PHP class definitions were required to exist inside of the public document root. While this is permissible in PHP, it generally tended to limit your integration points. This is because with many frameworks (and when following PHP best practices in general) it is unusual to have application code in a publicly accessible folder.
In the new Flash Builder for PHP you can now introspect your PHP objects much more easily and, thus, import them into your ActionScript code as value objects. While you still have the original mechanism to introspect your code, you now also have the ability to introspect objects that are outside of the document root. To do this follow these steps:
The Zend Studio introspection mechanism will read the PHP source file and do the heavy lifting of creating the PHP service for you. This mechanism makes connecting to PHP services outside of the document root much easier. After the class is introspected you will have value objects with all the methods and return values created based on any return values that have been provided.
At this point you can start adding service calls to your ActionScript code that invoke your remote PHP end point and begin binding Flex UI elements to the results of those PHP service calls.
You have a Flex project. You have a PHP project. Data is being passed back and forth flawlessly and you get to go home early, right? Hopefully, but the reality is that problems happen and handling errors on a remote connection is downright difficult.
Flash Builder for PHP integrates the workflow for debugging PHP applications into the workflow for debugging Flex applications. All you need to do is launch a Flex application with a new debug run configuration and you will be able to debug your PHP code right along with it.
Doing this is quite easy: Right-click your Flex application in the Package Explorer and choose Debug as > Web (PHP) Application (see Figure 4). This will launch your Flex application in a browser, preconfigured to kick off the PHP debug process when remote requests are made to your PHP application.
It’s a simple feature, but having personally had to debug a fair amount of Web 2.0 applications, I can say that the ability to just click a button on the front end and have the back end automatically start a debug session is a substantial time saver and a much more natural way to work with your application in development.
You’ve now had an introductory look at the new Flash Builder for PHP IDE and seen glimpses of its potential. As a PHP developer, I am quite excited at the opportunity to do more interesting and interactive work using Flash Builder for PHP for both the browser and the mobile Internet.
The first thing you will need is the Flash Builder for PHP IDE. If you are looking to provide feedback you can visit the forums. Additionally, you can download the sample files for this article and use the example applications to try out the new IDE. For more information on core Flash Builder 4.5 features, see What’s New in Flash Builder 4.5. For more information on core Zend Studio 8 features, see Zend Studio 8 Overview.
Flash Builder for PHP is a great opportunity for developers to build rich Flex applications with PHP-based data/business logic on a merged platform that enables you to develop using the best of both worlds in a seamless IDE.