Kohana, Subversion and the Eclipse IDE

Difficulty: Medium

In work I use Kohana with Subversion and Eclipse and I love it. I’m not saying its the best development environment but it really does suit my needs as a few of us can work on the same project together without breaking each others code. Plus I also enjoy IDE features such as refactoring, code completion, etc.

I’m not going to go into the pros and cons of why you should also use this setup but for anyone whose interested this is how to setup this development environment.

Getting Eclipse

Get Eclipse! This was originally a java only IDE but over the years has included support for other languages such as PHP and even Ruby. Once installed we have to set it up for PHP development. Open Eclipse and go to help > Software Updates > Find and install. Choose “Search for new features to Install”, add a new site, call it “PDT” (i.e. PHP Development Tools) and address is http://download.eclipse.org/tools/pdt/updates/. Follow the install instructions, its pretty straight forward.

Getting Subversion

Right now to Subversion. Subverison is a version control system, it keeps track of every change you make to your code so if you mess up you can always go back to the last working version of your project. I’m not going to guide you through installing Subversion as there are plenty of tutorials on the net. I really liked this one: http://www.jaredrichardson.net/articles/svn-cheat-sheet.html

Making Subversion work with Eclipse

Now that we have Subversion we need to get it working with Eclipse. For this we install a plugin for Eclipse called Subclipse. This is done by the same means as installing PDT above instead subsituting http://subclipse.tigris.org/update_1.2.x in the address field.

Importing Kohana into Eclipse

With all the above installed, reopen Eclipse and open the PHP perspective (click the funny little icon in the top right hand corner). Create a new PHP project and set the PHP version to 5. Right click in the PHP explorer window and select import. Navigate to your Kohana and select it. For the “Into Folder” option navigate to the PHP project you just created. You now have Kohana set up as a project in Eclipse!

Note

I have Xampp installed on my machine. I set the Eclipse working directory as a new folder in the same level as the htdocs folder. I then placed the Kohana index.php file into htdocs and edited it to point to my Kohana install. This allowed me to preview any changes I make on my localhost. You don’t have to follow the same root, do what suits you best.

Before I get onto the final section there is one thing you should do. In order for Eclipse to auto-suggest/complete Kohana classes and methods you need to add a file to your project (background info here). Create a PHP file in the application’s directory, call it _IDE_Helper.php. Copy and paste the following into the new file (big thanks to edam for this):

<?php die('No script access at all.');</code>
 
// This file is not intended to be executed. It's purpose is to help out various
// IDEs which can not tell that the Kohana classes whose names end with "_Core"
// can also be referred to without that suffix. Consequently they are unable to
// provide information about inherited methods and properties.
 
// libraries
class Archive extends Archive_Core { }
class Cache extends Cache_Core { }
class Calendar extends Calendar_Core { }
class Controller extends Controller_Core { }
class Database extends Database_Core { }
class Encrypt extends Encrypt_Core { }
class Image extends Image_Core { }
class Input extends Input_Core { }
class Loader extends Loader_Core { }
class Model extends Model_Core { }
class ORM extends ORM_Core { }
class Pagination extends Pagination_Core { }
class Payment extends Payment_Core { }
class Profiler extends Profiler_Core { }
class Router extends Router_Core { }
class Session extends Session_Core { }
class URI extends URI_Core { }
class User_agent extends User_agent_Core { }
class Validation extends Validation_Core { }
class View extends View_Core { }
 
// helpers
class arr extends arr_Core { }
class cookie extends cookie_Core { }
class date extends date_Core { }
class download extends download_Core { }
class email extends email_Core { }
class expires extends expires_Core { }
class feed extends feed_Core { }
class file extends file_Core { }
class form extends form_Core { }
class html extends html_Core { }
class inflector extends inflector_Core { }
class num extends num_Core { }
class security extends security_Core { }
class text extends text_Core { }
class url extends url_Core { }
class valid extends valid_Core { }
 
?>

Importing your Kohana project into Subversion

Finally all you have left to do is import your project into Subversion so that your team can work on it. So using the Subversion CLI navigate to where you want to create your respoitory. I recommend creating a repository for each project you intend to version control as version numbers are global so if you have two projects under the one repository they share the same version number.

Create the repository by typing: svnadmin create path/to/repository/name

Now the repository is created we need to share it, so enter the following in the CLI: svnserve -d -r path/to/repository/name

Ok, so now we have the repository created and served but we have yet to put anything in it. Using terminal (MAC) or cmd (WIN) navigate to your working directory and run the following:

svn import -m “importing project initial message” kohana svn://path/to/projects/repository

This imports your project into Subversion so that others can view/edit it. Check here for more info. The only thing to note is that “kohana” in the above line is the name of the project.

That’s it, finally. You now have your Kohana project integrated with Eclipse and version controlled. :)


22 Responses to “Kohana, Subversion and the Eclipse IDE”

  1. Mandos Says:

    Nic tutorial. Trick with _IDE_Helper.php helps much.

    One think. Its two subversion plugins for Eclipse:

    http://www.eclipseplugincentral.com/Web_Links-index-req-viewlink-cid-611.html

    http://www.eclipseplugincentral.com/Web_Links-index-req-viewlink-cid-47.html

    I’m using subversive but sometimes when I have few ‘extends subversive projects’ it’s faster to use windows client (comand line or TortoiseSVN)

  2. ghaez Says:

    Thanks for this post.

    Have you tested installation of PDT in new Eclipse 3.4.0? There is an issue with dependencies not working properly.

    Have you tested EasyEclipse for PHP? It’s very useful, but unfortunately it’s not too stable…

  3. ghaez Says:

    I feel pretty dumb right now, but I really couldn’t get it working. And I tried with latest Eclipse and previous too.

    There’s always something missing. Something about wst features or equinoxe features.

  4. ghaez Says:

    OK, seriously, I have no freakin’ idea how to get it working.
    It’s been about 5 hours of different approaches. Without success. Call me a moron if you want… :/

  5. neovive Says:

    If you do not currently use Eclipse for anything else, you may want to get started using the all-in-one Eclipse PDT download packages from Zend (http://www.zend.com/en/community/pdt). The download includes everything you need (except subversion) to get started — just unzip and get started.

  6. ghaez Says:

    Thanks neovive, the all-in-one package works fine.
    As you surely know, there is a nightly release of PDT 2.0. Has any of you tried to get it working? How is it?

  7. bennythemink Says:

    Hey ghaez,

    sorry I couldnt respond sooner but i was away all weekend. Im using Eclipse Europa v3.3.2

    what part of the above are you getting stuck on? give me some details and il do my best to help you out.

    @mandos, yip there’s two subversion plugins for eclipse alright. i was wondering which to use so after checking around it seemed like Subclipse was the most recommended. Although i havnt tested the above tutorial with both plugins, i see no reason why it wouldnt work with both :)

  8. ghaez Says:

    Hi bennythemink,
    I got stuck after I pasted the update URL you gave in the respective place and started installation. Eclipse told me that some of the featured cannot be installed because of some dependencies errors. Finally the PDT feature is not available.
    The all-in-one package that neovive linked to works, but I’m a bit confused. You wrote that you use refactoring and it just doesn’t work for PHP here. Also a feature called occurencies which highlights all occurencies of a variable/field in a file doesn’t seem to be here. And I find it very useful in EEfP. Is it a matter of configuration? I searched for this, but with no success.

  9. bennythemink Says:

    hey again ghaez,

    The update URL I have above is definitely correct, its the same one I used and its still the offical address presented in the PDT site, but there are other methods to install PDT (http://www.eclipse.org/pdt/install.php).

    Sorry about the refactoring, I’m just after realising I only used refactoring with Flex development and havn’t tried it with PHP yet. Sometimes you lose common-place/basic functionality between the different Eclipse perspectives which can be annoying.

    Occurencies is an example of the above, its a java perspective feature and not a PHP one. for an idea of what you can do in the PHP perspective go to window > preferences > PHP.

    -b

  10. ghaez Says:

    Yeah, I’ve visited the preferences settings many times.
    I’ve also sifted through the PDF home website.
    In EEfP I do have occurrancies in PHP perspective, that’s why I asked.
    To be honest, EEfP seems a lot better to me so far.
    Thanks for your time!

  11. bennythemink Says:

    is EEfP an IDE? i havnt heard of it before, but if its better that my current set up then I dont mind upgrading.

  12. ghaez Says:

    Yes, I mentioned it somewhere up there, so I thought it’s clear. By EEfP I mean EasyEclipse for PHP.
    http://easyeclipse.org/site/distributions/php.html
    It’s hard to say if it’s better. It better suits my needs.
    The editor has some bugs, e. g. the source view gets messed up when you paste a bigger piece of code. It’s the view only, it sometimes gets OK after a few seconds, sometimes I have to re-open the file.

  13. bennythemink Says:

    Thanks for the link ghaez, that EEfP looks very good. i will take a look into it once ive my current project finished.

  14. RastaTech Says:

    apropos to this, if you want to save yourself having to update the _IDE_Helper.php everytime you add a new class, you can use this brilliant little gem by PeterB:
    http://www.mapledesign.co.uk/code/kohana-zend-autocomplete/

    it came out of a discussion on the forum, here:http://forum.kohanaphp.com/comments.php?DiscussionID=230&page=1#Item_0

  15. RastaTech Says:

    oops let me repaste that last link:
    http://forum.kohanaphp.com/comments.php?DiscussionID=230&page=1#Item_0

  16. bennythemink Says:

    nice tip RastaTech, thanks.

  17. neovive Says:

    A few other good links on getting started with Eclipse:

    http://www.eioba.com/a74961/getting_started_with_eclipse_php_development_tools_pdt

    http://www.digitalbase.eu/blog/installing-eclipse-3-4-pdt-2-x-nightly-build

  18. Syndicut Says:

    I also use Kohana with Eclipse+PDT =)
    Thanks for the trick with IDE Helper!

  19. RastaTech Says:

    I’m using a pay4play version of eclipse called MyEclipse, that’s the std where I work because of its DB features; because of this I can’t use the PDT-all-in-one.
    Anyone know how I can get the PDT in there without? I too got several dependency errors when trying to install it via the install updates feature.
    I got PHPeclipse installed, but even though I included xdebug I can’t figure out how to do debugging of a PHP project, so I tried to put PDT in there as that has the zend debugger, but even after installing the zend debugger by itself, I get no PHP debug perspective.
    Gaaa, if I could just spend as much time working as I have been setting up an IDE, I’d be done by now…

  20. bennythemink Says:

    hey RastaTech,

    yes i can share your annoyance with setting up initial projects:( I only tried once to get the PDT/zend debugger working and i got nowhere with it after 4 hours of installing/uninstalling, configuring/reconfiguring.

    I have heard of other ppl who have managed to get the debugger working correctly but i dont have the time or patience to attempt it again any time soon.

    if your using a power-pc based mac then forget about PDT as it simply wont work.

    good look and sorry i cant be more help.

  21. RastaTech Says:

    Thanks BennyTheMink, I feel better knowing that I’m not just a moron who can’t install software! :)

  22. Chris Meller Says:

    Just FYI, for anyone having problems getting PDT setup with Eclipse or the Zend Debugger, I always download the PDT all-in-one package from Zend, which includes the Debugger already. Why do the work yourself when someone else has already done it? :)

    Link:
    http://www.zend.com/en/community/pdt

Leave a Comment