Saturday, October 16, 2010

Introduction to Kohana

When I started working with php frameworks, I began it with Code Igniter. Not so later I switched to Kohana, and I still actively use it in my everyday work. In the first post of my new blog I want to give a brief summary about the framework. What it is, what makes it unique and how does it basically work.



Kohana is a pretty minimalistic and lightweight framework. It is not (and it does not want to be) a heavyweight all-in-one stuff, it doesn't want to tell you how you should do things. In fact, the Kohana core is nothing else but only an autoloader, a router and some helper libraries.

When working with Kohana, you always have to keep an eye on the 3rd-party modules. The official Kohana distribution have some modules by default, but in fact these aren't more important then the 3rd-party ones. Use github, and look at the modules there, you will surely find some really useful ones, and don't reinvent the wheel..

As someone wrote recently on the kohana forum, "Kohana is made by experienced developers for experienced developers". If you have just started php, or you want to have tons of tutorials and step-by-step guides, then Kohana won't be the best choice for you. Kohana doesn't have a big user community, and there is not too much documentation about the framework. If you are a beginner - or not very experienced - user, then you have to look at the Kohana source many times. For advanced developers it mustn't be a problem, the Kohana core has small, very well documented and written source - but of course this method is not for beginners.

When you read a comparision about Kohana and something else, the lack of Kohana documentation will be surely mentioned as a disadvantage. In fact, I don't really see how could it be better. Kohana is small, and it's up to you how you use it. In my opinion it would be hard to write more about it.

When working with Kohana, it's a good approach to think about yourself as a Kohana developer, or at least as a contributor. Don't think that the core devs are better programmers then you, because they don't think that you are worse then them. Don't think about the devs and the community as a technology vendor whose product you use, but as a loosely coupled team of developers whose aim is to share their reusable codes with each other. This team has a small core codebase, and a lot of modules, which in most cases don't depend on each other. You can easily contribute to the core or share your own modules with the community. If something  doesn't fit your needs or you think that something can be implemented better, don't be afraid of starting a discussion about it in the forum or creating an issue at the project tracking application.

It's important to understand that Kohana is not about telling you how to do application development. It just gives you options, possibilities, alternatives. Let's take an example: an official Kohana distribution has got two backend-related modules, the lower level database module, and an ORM. If you don't prefer the official ORM, there are two 3rd-party ORM-s, Sprig and Jelly. If you don't like any of them, you can easily build your own backend on the top of the database module, or completely from scratch. It's also easy to integrate any php library as a Kohana module. If you are an experienced developer, it's really possible that you already have some self-written libs. You can easily use them with Kohana, and you won't have sleepless nights caused by autoloading issues, etc...

Kohana is a great core to build your own framework on. It's designed to be extremely extensible via it's cascading filesystem. Download Kohana, and check what you like and what you don't like in it. Check the available 3rd-party modules on github, and learn using the ones you would like to. Then implement your custom modules if you still have some further claims. This whole process will surely need significant time - but as I mentioned at the beginning, Kohana is not going to be an all-in-one framework that gives you everything out of the box.

If you are still interested in Kohana, here are some practical notes:


  • Kohana 2 and Kohana 3 (or KO3) are different frameworks. Tutorials written for Kohana 2 won't work with KO3, but it's not always easy for a beginner to decide what version is a tutorial for. Kohana 3.0.0 was released on 09/19/2009, anything written before it was surely written for Kohana 2.
  • to get started, you can find some useful links here
  • if you want to work with/on Kohana, it's strongly recommended to get familiar with git and github
  • read the forums intensively. Kohana is about the community. You can also join the #kohana room on FreeNode



That's all for now, happy coding ;)

1 comment: