Rian's Really Good Technoblog!

Kohana and Spam Sandwich

by rian on Jan.19, 2010, under Web Development

Firstly, let me apologize to anyone who may have left a genuine comment on the site.  The level of spam that I get in comments… is stunning.  Hundreds and hundreds every day.  And those are the ones that the automated filter doesn’t pick up.  The latest thing is to post something innocuous that ALMOST relates to the post… in the hope that I’ll just blindly approve it.

Spammers, call yourselves buzz marketers if you like, but there is a spot in hell with your name on it.

Anyway, I’m sure there were some genuine comments in there.  I just don’t have the time to trawl through them.  I’ll keep looking for a better way to manage that.  Comments are my favorite part of blogging.  This is like having a dinner party, and people keep showing up at the door dressed like the UPS man to say ‘Hi, your house very nice.  I appreciating it all time, dude. Buying V1aGr4 very cheap!!!’  Slam!

Now… on to technojunk!

Due to unforeseen circumstances, I have been thrust back into the world of PHP for a current engagement.  Without going into the pros and cons of PHP (truly, it has both), let’s just say that I’ll be using it.  That being the case, I’ve had to rather quickly decide on a development framework for the app… and boy howdy, are there a bunch of them these days.

Favorite slogan:
“The Zoop Framework: PHP development without the suck.”  Nice.

I dove in looking at some of the application framework comparisons (like this one on  Wikipedia) and came to the conclusion that a) there’s a LOT of them, and b) I was just going to have to pick one and get on with it.

So, I decided that I needed a few basic things to feel self-actualized:

  • PHP5
  • MVC
  • Extensibility
  • Object Relational Mapping (ORM)

This is old news, but PHP5 has a few notable advantages over PHP4 for my purposes:

  • Faster.  Faster’s better.
  • Passing by reference (PHP4 passed by value.  In a nutshell, that meant passing copies of things around instead of “the thing itself”.  That can be very, very confusing.
  • Greatly improved Object Model:
    • Visibility (Public, Protected, Private access)
    • Class methods and properties (no instance needed to access these, nice for utilities, factories, whatnot)
    • Interfaces, Abstracts, Finals… Oh boy! (These are basic OOP constructs that PHP4 just lacked)

That implies to me that a framework that isn’t based on PHP5 doesn’t take advantage of those things, and therefore is made more for compatibility than performance and robustness.

Model-View-Controller (MVC) is the cool kids’ way of structuring a web application so that there is separation in the code between those pieces that represent the “business model” of the thing (e.g., accounts, users, ratings, postings) from the presentation level (i.e., what you see what you use it).

Implementation-wise, the controller and view layer are separate, but in practice, they are pretty tightly coupled– you pretty much need to know in the controller what views you have and what they do exactly.  The really important separation is between that stuff and the model.  Your application design works so much better if you think of the underlying structure completely without regard for how you present it. Again, like PHP5, I don’t know anyone who doesn’t do this at this point.

On the other hand, there are more elaborate frameworks (e.g., Drupal) that are more like content management systems than web application frameworks purely.  I wasn’t interested in buying into the learning curve associated with such a system, and I also wanted a rather spare skeleton on which to build our system so that we understood how every piece worked and weren’t locked into another “product’s” development process.

Extensibility means that I want to be able to add modules to do various things without having to perform surgery on the framework itself.  For the most part, the basic frameworks allow this, but… never assume or you make an ASS out of U and ME.

Object relational mapping (ORM) is… well, it’s different things to different people, but… simply put, it provides a layer of abstraction between your objects and SQL so you don’t have to sprinkle nasty SQL snippets all over the place.  Also, the thing I was keen on was a way to describe relations (e.g., “belongs to”,”has many”) so (a oversimplified example) that I could just say:

thing1->thing2->name

instead of having to do something like

thing1->thing2_id
Thing2(thing2_id)->name

in a case where Thing1s have a Thing2 owning them.

Finally, the client had lots of experience with CodeIgniter.  That led me in that direction, but it fell a little short in that it’s not PHP5-based and doesn’t come with ORM (though, you can add it).  Turns out that there’s a nifty offshoot of that project called Kohana that does, indeed, meet all of my desired traits.

So, that’s what I’m doing.  Why Yii?  Why not PHP on Trax (get it?  Ruby on Rails in PHP?) I’ll tell you why.  I need to get some work done.  It seems to me that one could spend months evaluating the pros and cons of these things and get absolutely no work done.  My advice on most things: just pick one and go.  You can generally make any of them do anything you want to.  Once you’ve looked at the basics, you quickly digress into hair-splitting and procrastination, and I need NO help with that.

My experience so far?  I’m pretty happy with it.  It allows for nesting of templates so you can specify (ala Rails’ yield) an application layout into which you can insert a section template in which you can insert a page template… etc.  Performance is good.  PHP rewards the user for tolerating a lack of structure with a lot of flexibility, so there’s much less time spent trying to figure out type mismatches or other obscure minutiae that Java tends towards.

If I had my druthers, I’d have gone Grails for this project, but given the aforementioned constraints, that didn’t work out.  I think Kohana will provide a very nice alternative without requiring much from the system administrators, again unlike Java, which can creep dependencies into the server environment if you’re not careful.

I’ll report back as we progress on any interesting lessons that come up.  In the meantime, so far, so good.

:, , , , ,

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...