CodeIgniter and Controllers structure

October 20th, 2008

Over the weekend I was playing around with CodeIgniter. I was up and running pretty quickly and it all seemed to go pretty smoothly. Having built web applications and web sites for a number of years now and before that desktop applications etc, I’m usually pretty quick with establishing a technical structure for my site. I do this because I tend to work in iterations rather than focusing on one specific thing before moving on the next. Anyway, I became a bit frustrated when I noticed that I couldn’t subdivide my controllers folder. It seemed that I could only have one big pool of controllers. This was no good. I checked the documentation and at first I didn’t notice the section that describes how to divide your controllers folder into sub folders. When I finally had figured it out I ran into the next problem.

My site has a top level menu option called ‘Settings’. When you click ‘Settings’ I want to execute the ’settings’ controller located in the controllers/ folder. The Settings page however has more sub-options like Users, Groups, Roles etc. and I want all these controllers to live inside a settings/ folder that’s located in the controllers/ folder:

+ controllers/
   +settings/
      -users.php
      -groups.php
      -roles.php
   -settings.php

This was going to clash. Going to the localhost/myapp/settings URL would execute the ’settings’ controller and going to localhost/myapp/settings/users would bring up a 404 error page. I assume this is because the framework tries to execute a method called ‘users’ inside the ’settings’ controller.

Going back and forth with this issue I finally figured out a way to overcome this problem. In the routes.php configuration file you can set a default controller to execute. I’ve set mine to ‘index’. So, this could mean that if I would bring my settings.php file holder the Settings controller into the settings/ folder and rename it to index.php, it might execute that controller when browsing to localhost/mysite/settings. And behold, it does. the structure I ended up with was:

+ controllers/
   +settings/
      -index.php  <- default controller
      -users.php
      -groups.php
      -roles.php

I haven’t tried this yet with deeper structures but I assume that the same idea applies to that as well.

Eclipse Local History

September 10th, 2008

I’ve been a big fan of Eclipse for quite while now and every now and again I find a new feature that gets me more excited about Eclipse just a bit more.

The other day when I was working on this project I noticed in the Team folder of the right-click (context) menu of a file, the Local History option. I’d actually seen this option many times before but I never took any notice of it. The other day however I decided to click on it. When I did a tab opened that showed me some sort of history of the file I had selected when I selected the option. It was, not to my surprise, a local history of the file. Every time I had saved my file, Eclipse has kept a previous copy of it. Local History turns out to be a super undo. Awesome!

Now, Local History is not like version control. Local History is much more low level than that. Basically, Local History is your version control between commits. Sort of.

After discovering Local History I decided to have another quick peek at the other menu options. After a bit of clicking around I noticed that when I right clicked a folder, the option Restore From Local History… appeared. And just like the title implied, you can actually bring back deleted files. Not only that, you can actually select which version from the Local History of that file you’d like to bring back.

All in all, again I’m pretty impressed with Eclipse. If you happen to know any cool Eclipse features, please let me know!

New hosting

August 22nd, 2008

Just got myself some new hosting. I used to have my stuff hosted at MDWebhosting in Melbourne and they gave me a pretty good deal. However, I came across HawkHost and I just could resist their offering. Good storage, good bandwidth, unlimited add-on domains, unlimited sub-domains, unlimited databases (MySQL and PostgreSQL), the list goes on and on.

I also took the opertunity to get a new domain up and running. I used to use my opject.org domain but I thought maybe a name change couldn’t hurt. I’m always in for a bit of change (not to much though!). So, ther you go. I’m now reachable under NorthernBinary.org (because I’m from the northern hemisphere and I guess, a bit binary…).

Last but not least. I also took the oppertunity to upgrade to the latest version of Wordpress. Ah yeah, good ‘ol Wordpress. Not sure what the current version is, something like 2.6.1 or so.

Anyways, there is still some stuff to do. Getting rid of the default theme and some external depencies need to be resolved (images that are loaded etc.)

Busy busy busy…

Flash Remoting with AS3

July 26th, 2008

While staying on the topic of Flash Remoting. Using it with ActionScript 3 isn’t all that different. The basic building blocks are quite similar with those used in ActionScript 2. The main difference is that in ActionScript 3 there is a dedicated flash.net.Responder object that needs to be instantiated to receive the result from a AMF call. Knowing that, a bare bone ActionScript 3 Flash Remoting call would than look something like this:

import flash.events.NetStatusEvent;
import flash.net.NetConnection;
import flash.net.Responder;

function onConnectionStatus( event : NetStatusEvent ) : void
	{
		trace("onConnectionStatus " + event.info.level + ", " + event.info.code );
	}

function onResponderResult( result : String ) : void
	{
		trace("onResponderResult " + result);
	}

function onResponderStatus( event : NetStatusEvent ) : void
	{
		trace("onResponderStatus " + event.info.level + ", " + event.info.code );
	}

var responder : Responder;
responder = new Responder( onResponderResult, onResponderStatus );

var nc : NetConnection;
nc = new NetConnection();
nc.addEventListener( NetStatusEvent.NET_STATUS, onConnectionStatus);
nc.connect(http://localhost/remoting/gateway.php");
nc.call("HelloWorld.say", responder, "hello");

Flash Remoting

July 21st, 2008

I never really had the chance to use Flash Remoting on a commercial project and it has been years since I played around with it. It must have been 2003/2004 or so that I first tried using it. At the time I tried it with ColdFusion, which worked pretty OK, and with Java (JRun to be precise). I was pretty impressed with the level of abstraction that Flash Remoting provided. Not just from the ActionScript point of view but also from the server point of view. No more manual parsing of data structures. Great! Thinking about it, I can’t really understand why it isn’t more widely used. It seems that it is only used on the more corporate websites, or very specialized stuff to say the least, and you don’t see it much used with the ‘typical’ Flash stuff or hear much about it in the general Flash community. Maybe that’s because Flash Remoting is quite a techy thing to get your head around and that it’s out of the league of your typical Flashers. Maybe BlazeDS is going to make a change to this, but somehow I doubt that.

Anyways, I was playing with AMFPHP over the weekend. It was a fair bit of work to get it all up and running. The documentation on the site isn’t what you would call ‘good’ but after a bit of puzzling I was able to figure it out and was able to make a request through Remoting and get a result value back. Awesome. The next thing I wanted to do was to use a bare bone NetConnection instance to connect to AMFPHP. After all, in Flash it’s the only intrinsic object available to connect to an AMF server and somehow the Remoting classes provided by Adobe seem to be so incredibly complicated and not intuitive to use at all. Luckily they changed this for ActionScript 3, but I wanted to figure this out for ActionScript 2.

The first mistake I made was to focus on the connect method of the NetConnection object. I figured out that the NetConnection has an undocumented onStatus event handler. I figured also out that when I made a connection the onStatus wasn’t triggered when I used http, only when I used rtmp. Hmmm, that was kinda odd. I played around with it for a while and decided to move on to the next thing, which was calling a remote method. I created a simple HelloWorld method on the AMFPHP server and called it using the Remoting classes provided by Adobe. That worked fine. So I set up the following code using a bare bone NetConnection:

var responder : Object;
responder = new Object();
responder.onResult = function( result : String ) : Void
   {
      trace("responder:onResult " + result);
   };
responder.onStatus = function( info : Object ) : Void
   {
      trace("responder:onStatus " + info.code + ", " + info.level);
   };

var nc : NetConnection;
nc = new NetConnection();
nc.onStatus = function( info : Object ) : Void
   {
      trace("nc:onStatus " + info.code + ", " + info.level);
   };
nc.connect("http://localhost/remoting/gateway.php");
nc.call("HelloWorld.say", responder);

Now, this is where I went on my next wild goose chase. I spent the next couple of hours trying to figure out why this didn’t work. Going back and forth between the test case I did with the Adobe classes and this example. I just couldn’t figure out why the NetConnection example wasn’t working. I made dozens of small changes, trying to isolate the problem. But alas. Nothing. Until, at one point, I decided to change this line:

nc.call("HelloWorld.say", responder);

To this:

nc.call("HelloWorld.say", responder, "hello");

Bang! It worked. Apparently, just because the signature didn’t match previously with any remote function on the server, the function simply wasn’t called… Maybe it’s my naivety, but I was expecting the parameter to be just passed as an empty string, or null, if not specified. I’m currently not sure where the problem lies with that, but I guess it’s with AMFPHP. I think AMFPHP is to strict on signature testing and should be a bit more relaxed when it comes to that. I played around with it a bit more and decided to call it a day.

Today, while doing the dishes, or better, cleaning out the dishwasher the http/rtmp problem just solved itself. Of course the behavior was different! When connecting to an AMF server through http, the connection is stateless and can’t be maintained. In fact, calling the connect method on the NetConnection object doesn’t actually do that much and behaves completely different than with rtmp. It does call the server, but it seems to only check if the location, or gateway you want to call, exists. Only over an rtmp connection the Flash Player can maintain an open connection with the server. Duh!

I will definitely be using more Flash Remoting in the future and will most likely try to push it for more commercial projects from now on. It’s a great technology, saves heaps of bandwidth and no more XML/JSON parsing!

PHP

June 24th, 2008

I used to hate PHP. I still do actually, even if it’s only just a bit. But, over the past year or so I’ve developed an appreciation for the language. OK, as a programming language it is pretty odd. I mean that syntax, c’mon. Some weird demon child offspring between C and Perl. It’s a pretty hideous creature. Furthermore, PHP cannot be considered a platform like .NET or J2EE. It’s a programming language, nothing more and nothing less. Anything you can code with PHP can be done in as many different ways as there are PHP programmers. In a way it reminds me of the good old C days. C came with a massive library of incoherent functions. E.g. with C there where multiple of different ways of working with files. You use the set of functions that would make to most sense to you. In a sense, the biggest difference between PHP and C is the lack of pointers…

I believe that the power of PHP doesn’t lay in the programming language itself, because any serious programmer can confirm that the language is pretty frustrating to work with on a day to day basis. No, the power of PHP lies in its availability. A programming environment like ColdFusion, Java or even .NET is much more powerful and structured. Not that you can do more with these languages than with PHP, but it provides a common ground for programmers to start off with. The problem with ColdFusion and Java is that you can’t get it hosted, unless you’re willing to shell out the big bucks. Most providers offer Windows hosting so hosting ASP isn’t outside the reach of small time web developers and whipping up some old school ASP isn’t that much different than doing PHP. With .NET that’s a different story. Unfortunately, to effectively develop for .NET you need the Visual Studio development environment which you can buy for lots of money from Microsoft, making the platform unavailable for a large group of developers. I’m sure Micorsoft provides a stripped command-line SDK, but that doesn’t make the environment more approachable for people who don’t have the budget to buy Visual Studio.

The typical web developer likes PHP because every cheap hosting enviroment has at least PHP 4. And even though PHP 4 lacks some OO functionality, you can create pretty good applications with it. Other than that, there is so much information available for PHP available that’s being able to be grasped by not only the hard-core coders but also the the guy who just wants to store some stuff in a database and doesn’t want to get to much involved in the details of the language. Because of this, there are a lot of web developers using PHP. Which in turn means that a lot of companies use it because it has a large resource pool. So, even though PHP isn’t the most elegant programming language, it is popular because of these reasons.

(more) ActionScript 3 weirdness

May 7th, 2008

The other day I was attending the Colin Moock lecture “AS3 from the ground up” here in Sydney. Even though the lecture was very (and I mean very) basic, as it was intended, it was still quite interesting to see the man in action. I sat through the whole thing even though around 4 o’clock I was ready to walk out (of boredom). I’m glad I made it till the end.

Even though the lecture was quite basic there was one thing he pointed out that caught my attention. The implicit calling of the super class constructor. He’s stated that even if you do not specify a call to super in your sub class constructor, the super class constructor is still called. this sounded all to weird for me. I didn’t wanted to shout this out in case I was wrong and I didn’t bring a laptop to test out if this weird behavior was true. And thinking again, AS3 has a number of weird things going on that are not consistent with what you would expect. So, this might be another one of those things.

Never the less, the next day I decided to test this behavior just to make sure this was the case, and behold. It is. Besides the fact that you can’t make constructors private in AS3 (which is a different discussion all together) the super class constructor IS ALWAYS CALLED!!!

As a programmer, for me to override the constructor has actual meaning. It means that I DO NOT WANT THE SUPER CLASS CONSTRUCTOR TO EXECUTE, unless I call the super class constructor explicitly with the super keyword. To me this is another typical one of those; “we complier designers need to protect those poor little programmers from them selfs, the poor souls don’t know what they’re doing” type of thing. Sigh…

For some reason, the more I do with AS3 the the more frustrating it is becoming. Every time I run into small but irritating issues like this the more I tend to step away from the language. Don’t get me wrong, I like the executing speed increase and the improvement from AS2 its just these little annoying things that get to me.

The proprietary (in-house) CMS (revisited)

May 1st, 2008

I’m sure you’ve seen them. You might even have worked with them. The company with the proprietary CMS. Almost every company that specializes in web development has some sort of self proclaimed spectacular and ground breaking CMS that was developed in-house. My opinion? Try to avoid them!

Why? You ask. Well let me explain. Say you’re a developer and you’re being hired by one of these companies. It will be highly likely that they expect you to further develop this CMS or at least work with it. Most of the time this is almost impossible to do. I’ll bet you, there will be no documentation and the complete system architecture (if there is any) is probably all locked up inside one guy’s head (the guy who built it). Great. Now imagine you’re a client of a company with a proprietary CMS. I’m sure they will tell you that their CMS is the most fantastic and easy to use CMS in the world. It will solve all your problems. Unfortunately, you as the client has no way of actually testing if this statement is true, all you can do is believe them.

Now, in comes the established open source CMS. There are so many open source CMS’s out there that it’s almost not funny if you need to pick one. Just hop over to CMSMatrix and you’ll see what I mean. Currently the popular ones and my personal pet favorites are Drupal, Joomla! & Wordpress (For the moment we put aside the discussion if Wordpress is an CMS or not). Of course, the benefits of using an established open source CMS over a proprietary CMS is obvious:

  1. There will be documentation (for both end-users and developers).
  2. The implementation of features has been questioned during development (i.e. with all likelihood, more than one developer has worked on it and they discussed amongst each other the best way to implement certain features).
  3. The number of implementations will be much higher (i.e. real world examples).
  4. Clients are not locked in with a single development party.
  5. Clients are free to investigate the system before using it for their solution (transparency).
  6. Community (knowledge sharing).
  7. Jobs (for developers).

Well, I don’t know about you. But there’s not a lot that can compete with that and I’m sure that at least you will agree with me on most of these points. As a matter a fact, I can’t think of any benefit of using an proprietary CMS all together.

Of course, like most developers I would love to build a full fledged CMS myself. Heaps fun! But in the end its pointless. The market for CMS’s is completely over saturated and building your own can be considered a complete waste of time and effort. Now, by all means. I’m not claiming in any way that there is no room for proprietary CMS’s. Proprietary CMS’s are very suitable for the Amazon’s and eBay’s out there which are specialized systems, not generic ones.

As a developer, there is another very important aspect of proprietary CMS’s to consider. If you work for a company that utilizes a proprietary CMS, then whenever you would leave your position at that company, all your CMS knowledge will be worthless. On the other hand. If you had worked all that time with Drupal or Joomla! than you could actually utilize that knowledge in your next job. It might even be the case that you will be primarily hired for that knowledge.

eBooks

April 27th, 2008

Ever since I got involved with computers (20 or so years ago) I’ve always been buying books about various subjects to extend my knowledge and learn about new things. Over the years I’ve built up quite a little collection of books and a quick peek at my bookshelf learns me that there’s about 250 or so books there. Some them are really old. I mean really old! I think the oldest is called Using QuickBasic 4 and dates from 1987 (print). I think I’ve got a copy of it in 1989 or so (around the time of my QuickBasic era).

A couple of years ago I moved counties. I moved from the Netherlands to Australia. Guess what I took with me? I had about 11 boxes shipped over. 10 of them filled with books. So effectively I’ve been lugging this stuff half across the world.

I’ve always been intrigued with Safari (no, not the browser, but the service offering from O’Reilly). Getting a subscription to this service is very appealing to me. However, it still seems quite expensive. I do not buy books every month (I usually go through book buying phases). And since Safari is a monthly (or annual) subscription, I haven’t signed up yet. I believe that this sort of subscription/service is ideal for employers who employ programmers (hint hint).

Buying computer related books in Australia is a pretty expensive hobby. The average book goes for about $80 AUD. That’s currently about $75 USD! The average computer book on Amazon goes for about $35 USD ($ 38 AUD)!!! I guess buying in a normal store in the States doesn’t change the price that much and you get an actual physical book for that price. I guess that’s because of the shear volume of books being sold in the States is much higher than in Australia (1% of 300 million is a lot more than 1% of 22 million). Also, computer related books are not printed in Australia but overseas and have to be imported. On top of that the margin must be higher because less books will be sold in Australia and the shop owner still needs to pay the electricity bills of the book store (which doesn’t change whether you sell a 100 books or 10 books).

So, instead of buying physical books, I’ve been looking into cheaper alternatives. eBooks are a great thing. Not only are they cheaper to buy but also a hell of a lot cheaper to ship to the other side of the world. In the recent month I’ve bought eBooks from four different publishers. O’Reilly, Packt Publishing, Manning and Apress. My best experience so far is with Manning.

All the publishers so far had me create an account before I could purchase my eBook. I can see their point of view of this. By creating an account, my purchase is associated with my account. E.g. with O’Reilly I can go back into my account and download my eBook over and over again. This is handy if I ever delete my eBook by mistake, for me, Manning has succeeded the best with mimicking the real live event of buying a book. When you buy an eBook on Manning’s site and you pay with PayPal (yes, PayPal is awesome!) you don’t have to create an account. All you need to do is to click on the pay with PayPal button, which guides you through the familiar PayPal process, and the book is emailed to the email address that’s associated with you PayPal account. So yes. they have your email address but so what? So do the others with a lot more information. Not to mention the time I had to spend setting up the account, which of course next time I want to purchase an eBook I’ve forgotten the password of.

Now being true geeks you probably wonder what eBooks I purchased. This is the list:

So there you go. Lots of stuff about Joomla! and CMS related things plus a bit of Java to top it off (anything Java is still my favorite). I’ll be reading a lot for the next coming weeks. Maybe I can squeeze out another post with my thoughts on proprietary (or in-house) developed CMS systems. Have fun buying eBooks and till next time.

WebDU 2008

April 12th, 2008

Somehow I’ve been able to get my big fat head on the WebDU about page! I’m the one looking straight into the camera and my buddy Dave is sitting right next to me. Man, that was a shock when I saw that page for the first time. Funny enough I remember that photo being taken and who took it!

Unfortunately I will not be able to attend WebDU this year. Maybe next year again…