Why/When Should I Use Kohana?
Kohana is a small PHP MVC framework that is incredibly powerful, yet lightweight. I see it more like PHP+ than some of the other PHP frameworks.
The purpose of an MVC framework is to abstract the high-level programming language into more of an application-level programming language. The framework provides a number of building blocks that enable you to get up-to-speed more quickly and fill in some of the gaps in the underlying language. I’ve been around PHP since v3 so I’ve seen a lot of changes with v4 and v5 but there are gaps. Every time I build a new site there are a basic set of classes that have to be developed such as an Error Handler, Logging Subsystem, Database Abstraction, HTML Helpers, Templating and Form Handlers. And above all of that there is a constant thread of Information Security classes that have to be built in to cope with XSS and SQL Injection attacks. Session Management is typically another item on the to-do list.
Why spend all of that time building all of these classes or re-using code from other projects when I can use a framework? If my project needs these components I immediately pull out the framework and start work on the real objective, writing the application not the spending weeks on the underlying codebase.
CodeIgniter was my first introduction to the PHP MVC framework, it was quick and did just enough of the basics. The other frameworks such as Symfony, CakePHP and Zend had too much overhead — they all abstracted the programming language even further than CodeIgniter and Kohana. Symfony, CakePHP and Zend are like comparing Visual Basic to Visual C++. They’re higher-level frameworks which means the time to prototype an application is far less than a mid-level framework but the cost is computational overhead. There are plenty of benchmarks around the Internet comparing these frameworks but no matter how flawed the benchmark logic is there is always a clear divide between the mid and high level frameworks.
My sites ultimately end up in production, they’re not prototypes for a client and I hate having to redo work. I would hate to launch a site in Zend and then have to re-code it later in another faster framework or in pure PHP. I don’t need to do that with Kohana. The disadvantage is that I have to invest more time building the prototype application but in the long-run I get the benefit. When the site reaches production I’m able to scale the site more easily as the resource requirements on the server are less. My visitors, users or customers are happier because the site is quicker.
As for how to choose between CodeIgniter and Kohana?
Kohana is originally a fork of CodeIgniter. I went with it because I wanted a framework that was based on PHP v5, not v4. There were a number of significant changes in the PHP language that made programming far easier so I decided to take the less-trodden path. Two years ago when I made my choice, it was easy. Today it’s harder as CodeIgniter v2.0 is now based around PHP v5 but Kohana has since moved on to v3. I also think that Kohana is starting to evolve beyond the constraints of v2 and the typical criticism of a lack of documentation.
Kohana’s documentation and examples in the wild are very limited, you really will spend hours of time tracing bugs and reading the source code to understand what you’re supposed to do. CodeIgniter lets you avoid all of that as there’s very good documentation, lots of examples and a strong community. Kohana’s community used to be full of people that said ‘read the source code’, today it’s a slightly friendlier environment.
I have a new project coming up that I intend to use Kohana for. I’ll code up a few examples in CodeIgniter and Kohana and post the results. I’m sure the code in Kohana will be cleaner and easier to understand as there’s less fluff involved but it will be an interesting learning exercise.
No related posts.
-
Meta