Doggetto.com

January 4, 2010

How I Use Netbeans 6.8 and Symfony 1.2

Filed under: Personal,symfony Framework,Technology — Tags: , — NoCoolName_Tom @ 2:02 pm

Beans

I am expirementing with using a full-fledged IDE for web development at work. Until recently I used gEdit; most people don’t know that gEdit can be extended via plugins to become a fantastic development environment. However, one thing I could never get to work was auto-completion based upon functions and classes in PHP. However, the speed of using gEdit, as opposed to Eclipse, was amazing and I never could quite get the hang of editors like Aptana and Eclipse. Recently, I found that Sun’s Java-based IDE, NetBeans, had added symfony support and I wondered how useful that might be. I tried it and loved it. Using NetBeans is not without issues, however. It’s still a bit buggy (that might be because I’m using the development code) and memory usage is about what you’d expect from a Java-based editor (ie, sometimes really, really high). Still, it’s worked out quite well and I’d recommend giving it a try.

Here’s how I set up my installation of NetBeans. I am running Ubuntu Karmic Koala (9.10).

1. Download Netbeans 6.8 for PHP from netbeans.org
2. Install to /opt/NetBeans
Run the following code to prep the installation directory:

sudo mkdir /opt/NetBeans;
sudo chmod 777 /opt/NetBeans;

Then run the following from a terminal wherever you saved the NetBeans installation file:

chmod +x <netbeans_file>.download;
./<netbeans_file>.download;

This will begin the installation.

Be certain to change the installation from your home directory to /opt/NetBeans!

NetBeans should install itself to the desktop as an icon and to the menu under “Programming”. To uninstall it at any later time simply run:

sh /opt/NetBeans/uninstall.sh;

This will remove the program. To fully remove it, also remove the configuration directories at: ~/.netbeans, ~/.netbeans-registration, and ~/NetBeansProjects.

3.Configure NetBeans.
symfony functionality was included in NetBeans 6.8 so it doesn’t require a plugin in this or later versions. However, it does require some setup to work correctly. Run Netbeans, and go to the Options dialogue (Tools > Options). In the PHP section, go to the Symfony tab. In the Symfony script field, find or enter the path for the symfony script in your local framework installation; don’t refrence the batch file, but rather the one without an extension. Mine is installed at: /usr/share/php/symfony/symfony12/data/bin/symfony

Since we’re likely to be in the middle of a project we’ll set up NetBeans to use this project. In the future, you can set up a symfony project from NetBeans (which will run commands such as “symfony generate:project” and “symfony generate:app” for you).

Start a new project (File > New Project). Choose to create a “PHP Application with Existing Sources”. Click “Next”. Set the source folder to the project’s root folder. It’s best to place the NetBeans metadata in a seperate folder outside of the project. The default for this is within your home directory and will work fine. Click “Next”. If you wish you can set up the accesible URL for your project here (or you can do so as part of the full project configuration later).

NetBeans will, upon analyzing the project, determine that it is a symfony project. However, to have full symfony help, you’ll need to add the framework to the Project Include Path for the project and the project cache. (Yes, this is kinda stupid at first, but it will be a lifesaver!) To add to the Include Path, right-click on the Include Path in the Project Display Pane (should be, by default, the pane in the upper-left; the Include Path should be at the bottom of the list.) I add the cache directory of the project and the lib directory of the framework (for me, this is: /usr/share/php/symfony/symfony12/lib). Once these are added and scanned, their functions should be available in the on-screen tooltips as you type. The reason to add these directories (especially the framework) are because it is expected that we might be editing non-Symfony files with the editor and we don’t want functions and classes that are not accessible to the script to be displayed.

Once you have the project up, to finish your configuration, right click on the project name in the Project Display Pane and select “Properties”. On “Sources” make sure that the Source Folder is the root of the symfony project. You can change the “Test Folder” to the test folder within the project. Set the web root to the web folder within the project. Go to the “Run Configuration” bullet point. Ensure that the Project URL is correct for accessing the application. Once the URL path is set, choose one of the application_dev.php files within the web directory of the project for the “Index File”.

Some of the fun aspects of the new IDE: besides having accurate tooltips about variables and functions, you have the ability to jump (via a right-click) between actions and views. This can be very useful at times when you are trying to track down a particular bug. Another fun trick is to Ctrl-click on a function or a class name: you will jump to that item’s declaration.

That should do it for you! If you have xdebug installed, you should also be able to use the build-in debugger (I haven’t really used it yet, but can already tell just how useful it will be).

6 Comments »

  1. This was helpful. Thank you.

    Comment by irishfury — January 17, 2010 @ 11:59 pm

  2. Very helpful adding the cache folder to the includes lib, as NB 6.8 excludes the cache folder from the project list. It’s nice to be able to jump (CTRL click) to the autoxxxActions to see what’s going on before you start to overwrite a method.

    Thanks again!

    Comment by Sean — February 12, 2010 @ 9:21 pm

  3. Hi, i have try to remove netbeans 6.8 using method above however it doesn’t work. Then i try go to directory ~/netbeans-6.8# ./uninstall.sh and it working..

    Comment by aremint — March 8, 2010 @ 10:13 pm

  4. The uninstallation script should be in the directory where you installed NetBeans. In my particular directions I overwrote that directory to place NetBeans inside of /opt (I like to put programs that are self-contained in there). NetBeans likes to be placed in the home directory by default however (I just don’t like filling home with applications – seems more like a data location to me). As long as you run the uninstall.sh script it should remove NetBeans.

    If need to search for the file see if locate has indexed the file:

    locate uninstall.sh;

    If it hasn’t indexed it and/or you can’t find it that way, try using find. This will probably take a while, but it’ll find it:

    find / -iname 'uninstall.sh';

    Once you’ve found it execute it and it should remove the NetBeans installations (make SURE that it is within the NetBeans installation folder when you find it – you don’t want to delete something else!)

    Comment by NoCoolName_Tom — March 13, 2010 @ 6:09 pm

  5. Excellent description, worked like a charm in 6.9.1, thanks.

    Comment by jeff langley — October 3, 2010 @ 7:12 pm

  6. I use free PHP IDE Codelobster PHP Edition. It has special plug-in for Symfony framework.

    Comment by Stas — March 9, 2011 @ 4:17 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress