If you’re a multi-disciplined developer, like myself; then you probably develop some, if not all of the code for both the front and back-end. The problem I experienced though was while it was easy to develop Zend framework based solutions within Eclipse / Aptana. It wasn’t very user-friendly when it came to harnessing the automation side of setting up and extending a Zend framework project via the Zend_Tool command line tools. Fortunately I happened to stumble across this article by Madarco where he details how to add this as an external tool. It was a great starting point for me, but wasn’t as flexible as I wanted – so I decided to try and streamline it a bit more so it wasn’t so tightly tied to a specific project as his article prescribes.
For clarity I have reproduced the steps to set this up from scratch, (as per Madarco’s guide), purely as my enhancements slot in at various points and it would likely become very confusing to try and decipher where and when you added my updates in to the original steps. I still highly recommend reading Madarco’s article as it was the inspiration behind this one.
The first thing you’ll need to do is download the latest version of the Zend framework (as of writing this it was 1.10.1), extract the archive to your local web server – in my case this is MAMP Pro, but you can use pretty much any web server. If you have PHP installed as part of your system configuration (i.e. on Linux or Mac OSX), then you can put this pretty much anywhere on your machine – the main thing is that you can run PHP from the command line.
The next step is to open up Eclipse and from the main menu select Run > External Tools > External Tools Configuration This will open the dialog for configuring as the name implies, any external tools. From here you’re going to do the following:
- Create a new external tool entry
- Add in the reference to the Zend_Tool command line script / executable
- Provide location specific variables to enable the script to run correctly
- Update the working directory information and assign the relevant variables to Zend_Tool itself
- Save and test it
If this sounds a little complicated? It isn’t but to make it easier to follow I’ve included screen shots to help.
So the first step is to create a new external tool entry by clicking the New Entry icon (indicated by the icon). Give the new entry a meaningful name – I opted for Zend_Tool and with the Main tab selected add in the full path to the Zend_Tool script (if you’re on Linux or a Mac), or the executable, (if you’re on Windows) to the location field as illustrated below.
Next you need to define the workspace. Here we’re going to use variables instead of fixed values. This allows more flexibility and means you won’t have to keep updating the command every time you create a project. So in the Working Directory field add ${selected_resource_loc}
This provides the location of a selected resource (folder, file etc) within an Eclipse/ Aptana project providing the flexibility needed to use all of various commands that the Zend Tool supports. The last element to add in this tab is the arguments that will be passed to the Zend Tool itself.
Bear in mind that most commands require two parameters. However we will only pass the values set in the dialog box that the external tool command will open. So just add ${string_prompt} to this field.
You’re almost finished, as the command, the parameters and the arguments are set, you just need to set the refresh options and update the environment. So let’s deal with the refresh options first. Switch to the Refresh tab and set it to the same values as the image below.
You don’t need to do anything with the Build tab so skip it and select the Environment tab as you need to add in a couple of variables for the command to function correctly. Click the New button and name the variable Path and set it’s value to the location of your PHP binary (as I’m testing using a local web server mine points to my MAMP installation of PHP). The second variable should be called ZEND_TOOL_INCLUDE_PATH_PREPEND and it’s value should point to your Zend framework library; again I have mine centralized so it points to that version. However you will probably want to point it to the same location as the Zend Tool command.
Once assigned yours will probably look something like this
UPDATE
It looks like you can omit the ZEND_TOOL_INCLUDE_PATH_PREPEND entry from your configuration – at least you can on Mac OS X.
Lastly switch to the Common tab and make sure you check the External Tools entry in the Display in favourites menu and you can click close as the command is complete. Next we need to test it.
Create a new PHP project and with the project entry selected and click on the external tools icon in the menu bar and select your Zend Tool entry. When you click on it a dialog will open with an input field in it. In the text field put the following information create project src. What this will do is create the Zend framework scaffolding in a folder called src in the root of your project and refresh the project to show the updates have happened. What the options in the command also let you do is if you now select the src folder and run the tool again, but this time use the create model TestModel the command will run correctly and add the model to the model directory in the application folder.
Other common commands include:
- create controller
- create view
- create model
- create layout
- enable layout
That’s pretty much it – there are a lot of commands you can run via the Zend Tool and to be honest I haven’t tested them all, but they should work. One thing I will say though is you need to remember that the tool requires two parameters the command and the value, so in the case of the create project command I supplied src as the value, the down side is that the way we configured this external command entry you can’t use it to make the project scaffold in the root of the project, it has to have a sub folder – Not a big issue IMHO.
One Comment