Accessibility

Table of Contents

Working with Flex and PHP in Eclipse

Creating a Flex and PHP project

Now you are ready to create a project in Zend Studio that can be used for both Flex and PHP code. Flex Builder has a Flex project type named PHP. If you create this type of project, it will have only a Flex nature and not a PHP nature, thus some PHP features provided by the Zend Studio will not be available for your project.

To have both natures, first create your PHP project. Choose File > New > Project (see Figure 2). In the wizard select PHP > PHP project (see Figure 3) and then click Next. When the PHP Project wizard opens, specify a project name (in this example I used flex_project) and select Enable project specific settings. Click Finish (see Figure 4).

Opening the New Project Wizard

Figure 2. Opening the New Project Wizard

Choosing the PHP Project type

Figure 3. Choosing the PHP Project type

The PHP project wizard

Figure 4. The PHP project wizard

Once you have created the project, right-click on it and choose Flex Project Nature > Add Flex Project Nature (see Figure 5). This wizard will add Flex nature to your PHP project, so you will be able to create Flex applications and compile them as you would in any Flex project.

Adding the Flex Project Nature

Figure 5. Adding the Flex Project Nature

Clicking Add Flex Project Nature starts a wizard that looks very similar to the new Flex Project Wizard. Select PHP as the Application server type and then click Next (see Figure 6).

The first page of the Add Flex nature wizard

Figure 6. The first page of the Add Flex nature wizard

On the second page of the wizard (see Figure 7), enter the path to your web root folder and the URL for this path. For example, on my machine these are c:\htdocs and http://localhost.

The final page of the Add Flex nature wizard

Figure 7. The final page of the Add Flex nature wizard

You could also use a network path or a folder that is under your web server root. For example, maybe you have a folder named tests under your root server. In this case the values will be c:\htdocs\tests and http://localhost/tests. After you enter these values, click Validate Configuration. If your server has not started, or if you mispelled the URL or the web root location, you will see a warning. Click Finish when you are done. You should now have a project like the one shown in Figure 8.

The combined Flex and PHP project

Figure 8. The combined Flex and PHP project

A few notes on these last steps:

  • If you want to create an AIR – PHP project, you need a different approach that involves some additional work. The reason is that the Add Flex Nature wizard doesn’t support AIR projects; it supports only Flex, Flex Library, and ActionScript projects. But if you work a little bit, you can do it yourself. For this, first you create the AIR project you want. Then create a PHP project. Eclipse uses a special file, named .project, inside each project to track the natures of the project. Copy the nature and build command nodes from the PHP .project file to the AIR .project file and you are done.
  • Why choose PHP for the application server type in the Add Flex Nature wizard? As you remember the wizard asks for the location and URL of the web server. Flex Builder uses this information to place the compiled Flex application under the path you provided and to launch it from there using the URL you provided. Basically it streamlines the deployment tasks, so you don’t need to manually copy the SWF files, open the browser, or remember the correct URL.