PHPEclipse and Model View Controller

Update

As of this writing the nightly build is being built and the change is mainstream. You need the nightly (1.2.0) update site: http://update.phpeclipse.net/update/nightly
Thanks to ajt and ed_mann for making this possible!

I’ve been using eclipse and phpeclipse for some time now for my PHP related developments. One of the biggest productivity killers for me was that the browser preview always tries to preview your just edited PHP file, which in a model view controller application is utter nonsense. Just because I’m just editing controller.php doesn’t mean I want to preview http://localhost/project/controller.php. Instead this usually means I’d like to view http://localhost or http://localhost/mypage. This forced me to switch to firefox after every modification and reload the page there. What I would really like to see here is the automatic reloading, in firefox or if this is not possible in the internal preview (I think I have recently read somewhere that phpeclipse doesn’t support a preview on external browsers anyway).

I already made a feature request for this. You should be able to choose your own URL since the default behavior is nonsense for MVC apps (which I would hope most people do). Somehow I had the feeling that this will take a while, if it gets done at all. If the majority of phpeclipse users is satisfied with the way it is, it will never get mainstream.

So I sat down and tried it on my own. I’m totally new to eclipse plugin development but somehow I managed to find the relevant code in phpeclipse (which btw. is a huge codebase!) and after some more thinking I figured something out that wouldn’t force me to introduce an option (which would be a pain for me since I’m really totally new to PDE). So I implemented an educated guess: If you haven’t previewed anything before, the behavior is as always. With an MVC app this first preview will be nonsense. But after a URL has been loaded in the preview, on every save in every file it will just reload that page. So you can just edit the URL in the preview to point to whatever is interesting to you at this point, edit any file in your project and have it reloaded. You can change this URL any time.

Installation

If you are interested in the code patch (it’s only a couple of lines) leave a comment and I will send it to you or publish it here.

Have fun!

Tags: , , , , ,

2 Responses to “PHPEclipse and Model View Controller”

Leave a Reply


uberdose 2.0

L-l-look at you, hacker.