Running PHP Eclipse with FDT / FB & Ant

OK, so lately I have been doing a lot of work in both FDT & Flash builder and building data centric applications with PHP and mySQL back ends, it has been vital that my work flow has been up to scratch to ensure that these project’s deadlines have been met and also so that I don’t go crazy doing loads of crap that I don’t need to do! As I have been very pleased with the ways things have run I though it best to share my set up with a wider audience.

Primarily I code in FDT so I am going to concentrate this walk through on my FDT set up, but if necessary I will direct any Flash builder relevant stuff in the right direction also seeing as that has also been a major part of it.

I am going to assume you already have FDT installed, which thankfully comes with ANT out of the box so there is no need for any set up here, however if you are using Flash builder or even Flex builder, unfortunately you will be lacking ANT support and so will need to be installed seperately. Thankfully this has been well documented and so if you google it you will find many blogs explaining the process or you can always click here and follow the run through.

Now so that we can code our PHP in FDT or FB with some great auto completion and almost FDT style live error highlighting we need to also install another plugin to our set up and this is PHPEclipse. To install this you simply go to Help/install new software and once the dialogue window opens up.

Here you will need to click the ‘Add’ button to add a new site. In the new site dialogue window that pops up enter a name for your site like PHPEclipse or something and enter this url: “http://update.phpeclipse.net/update/stable/1.2.x” then click OK. Then make sure it is chosen from the drop down and wait for it to connect and download the relevant data. Then click the box next to ‘PHPEclipse Stable Builds’, click next, next again, then accept the agreement and then wait for it to install. Once installed FDT or FB will need to be restarted. In the mean time we need to get a local server set up so that we can run PHP and mySQL directly from our development computer.

If you are on a PC then you can choose xampp or wamp or if you are on a mac then you can install mamp either way you want to download the installer and get these installed. During installation they should ask where you want to locate the root folders for the installation, I normally go for the c drive that way it is easy to find. The root folder will be sat within these directories, so on xampp, which is what I have installed it is C://xampp/htdocs. To get more info once you have the service installed and running, go to a browser window, type in http://localhost and it should connect directly to your root folder’s bootstrap file and all the relevant information should be display there.

Now the main reason for all this for me, is when I am creating PHP scripts as part of a flash project I want to make sure that I have all my files together, rather than creating one project in the localhost root folder to test all my PHP scripts and a separate Flash project set up in my FDT dev folder. With the power of ANT I can develop PHP and Flash in the same project together side by side. So lets dig into to developing with PHP and FDT.

Open up FDT and you will notice that you can now access another perspective for PHPEclipse. This gives you some great functionality, such as being able to stop and start xampp services from within the Eclipse environment, viewing your script via the built in PHP browser, which targets by default your local host folder. You will notice also that coding PHP in PHPEclipse is also a breeze and makes coding PHP much more fun. So lets get back into the FDT perspective and start a new project to test our work flow. Call it what ever you want and just target pure AS3 and which ever SDK you want. Create a new class and call it whatever you want and after your constructor create a new function which will instantiate a URLLoader to target what will soon be a PHP script in our local host folder:

ActionScript
< view plain text >
  1. private function init() : void
  2.         {
  3.             var url:URLRequest = new URLRequest("http://localhost/test/returnVal.php");
  4.             var urlLoader : URLLoader = new URLLoader();
  5.             urlLoader.addEventListener(Event.COMPLETE, loaded);
  6.             urlLoader.load(url);
  7.         }
  8.  
  9.         private function loaded(event : Event) : void
  10.         {
  11.             trace(event.target.data);
  12.         }

As you can see we will be targeting a php script in our localhost root called returnVal.php, so lets get creating and testing it. Change your perspective to PHPEclipse and in your FDT project src folder create a new folder called ‘php’. Then right click it, and select ‘new PHP file’ and give it a name of returnVal.php, press enter and the file is created. For the purpose of this run through, we are just going to echo a simple success statement:

  1. echo "Successfully sent data from local host";

Now we need to test this script which currently is sitting in our FDT project folder but need to run in a PHP environment, so with the help of ANT we are going to instantly copy this file into our local host root. If you haven’t used ANT before, I urge you to give it ago, you can get more details here. It simplifies tasks such as this to reduce the amount of extra work you would need to do like opening a folder and copying files each time it changes to run and test it. With ANT it is simply a click within FDT and the file is copied. The file we will be using is very simple and is made of the following:

ActionScript
< view plain text >
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project default="1. Copy to local host" name="Copy PHP Script">
  3.     <!-- Path to local host files -->
  4.     <property name="local_host_dir" value="C:\xampp\htdocs\test" />
  5.     <!-- Path to project php folder -->
  6.     <property name="target_directory" value="${basedir}/src/php"/>
  7.     <!-- Copy files to relevant directory -->
  8.     <target name="1. Copy to local host" description="clean up">
  9.         <copy todir="${local_host_dir}">
  10.             <fileset dir="${target_directory}">
  11.             </fileset>
  12.           </copy>
  13.     </target>
  14. </project>

The ant file sits in your project root and to activate it, make sure you have an ANT window within your perspective, and just drag the file over to it. The above xml data will appear as one task called ’1. Copy to local host’. If you click this you will see the script start to build in the console window and presto! the files should be copied over to a new folder in your local host root called ‘test’. Now if you type the url ‘http://localhost/test/returnVal.php’ in your PHPEclipse perspective’s PHP browser window you will see the success message displayed in the browser window, meaning that everything is working perfectly.
Lets now go back into our FDT perspective, debug our application and you should get a trace statement made up of the success message from the php script running in localhost’s root! This whole process as you can see smooths out the whole php script writing process with your flash applications, whilst also keeping your project folder structure solid.

All files for this run through are available here including the ant script.

This entry was posted in Actionscript 3.0, FDT and tagged , , . Bookmark the permalink.

One Response to Running PHP Eclipse with FDT / FB & Ant

  1. Pingback: Tweets that mention Running PHP Eclipse with FDT / FB & Ant | UltraVisual Blog -- Topsy.com

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>