views:

11568

answers:

15

Hi All,

I usually just work with straight PHP, but want to try MVC and see if a framework will really speed up development.

After much waffling, analysis paralysis, and many dumb SO questions, I thought I had settled on CodeIgniter for my next PHP project.

However, I am now seriously considering Kohana.

Has anyone made the switch from CI to Kohana? If so, why?

What's better about the actual code, libraries, etc?


Edit:

Hi All,

I did end up going with Kohana.

It's easy to use, but more importantly, it's easy NOT to use, since there are a lot of things I like to work with native PHP for. It's ridiculously extensible, well coded, and seems like it is beginning to pull out ahead of CI in a few things like putting views in views, passing subview data, etc.

I am sure CI will catch up, but Kohana should be 3 steps ahead by then =o)

+9  A: 

I spent 2 months trying to work with Kohana and there were a few issues that were so irritating that I gave it up completely, although they weren't all directly related to the code.

For one, the community around it is very small so there is not much in the way of support. The documentation is also not particularly helpful and the tutorials at times don't actually work.

They also don't have a very clear roadmap and don't seem to consider backwards compatibility, so for example some applications that worked with 2.0 won't work with 2.1.

Kohana doesn't support MSSQL, Oracle, or ODBC like CodeIgniter does.

On the other hand, the fact that it supports PHP 5 rather than PHP4 was a major plus for me and was one of the main reasons I tried it out in the first place.

I would personally not use it professionally, but maybe it would be interesting to use it on small personal projects. YMMV, ofc.

I haven't used Kohana, but when someone asks me why I use CI I always name the community and the superb documentation.
JAG
As far as I can see, Kohana supports PDO, which supports MSSQL, Oracle, ODBC and more -- http://www.php.net/manual/en/pdo.drivers.php
Svish
+1  A: 

I havent tried Kohana, but CodeIgniter has been good to me so far

Mukthar
+2  A: 

I was going to use CI on a project, but I ended up using Kohana. Kohana worked very well--my client is happy and so am I. I stayed away from the ORM and so on. I mostly made use of the MVC setup, router and some helpers and such. If I wasn't in love with Ruby I'd use it again.

dylanfm
+6  A: 

Kohana was my first venture into using a pre-rolled framework, after checking out codeigniter but being unsatisfied with the php4 conventions. I would never consider a giant framework suck as cake/zend/symnfony.

My experience is only good. I make minimal use of ORM, but that's just my preference. I find every other aspect extremely useful and streamlined. Granted a project written on 2.2 will not work on 2.3, but it's not as if there was a problem with 2.2 anyway. Stick with and and just upgrade for new projects! It's nice to see some developers who are willing to break backwards compatability in order to make serious advances for a change!

Just my 2p. Pete

+7  A: 

Kohana has cleaner code under the hood and is PHP 5 only (which is a plus), but if you're not willing to closely keep track of changes you'll find your code stop working. They do major API changes without consulting their community for input and every new version usually renders the previous ones obsolete. CI is much more stable if you can put up with the PHP 4 aspect, but Kohana's routing and other features in general are much more superior.

+8  A: 

CI is "stable" because it rarely changes. Is this a good thing? CI's community is large but very watered down. For every intelligent post there are 10 people with limited PHP knowlege asking how to make the next flickr. If you are new to PHP and frameworks perhaps you can benefit from that type of community but I find the much smaller but more knowlegeable community of Kohana to be of greater benefit. Kohana is a much cleaner coded and far more extensible framework. This was the main reason I switched.

+47  A: 

I have used CI, Kohana and Zend:

CI is good for newbies. It gives a nice intro to a couple of concepts. However, if you have time to improve as a developer and keep learning about architecture and new techniques, you'll grow tired of it after a while. Some people don't have this luxury, they work in web firms that use them like coding mules. Production, production, production. No time to recycle your knowledge. In such cases, CI usually gives the illusion to be a masterpiece.

Pros: PHP4 (this is a pro depending whom you ask) compatible with PHP5, fast on benchmarks, simple, nice doc, light footprint, low learning curve, friendly community (although i have noticed an increasing tendency for some seasoned users to pick on newbies), sponsored by a company, will be the underlying framework for the upcoming Expression Engine 2 cms.

Cons: PHP4 so doesn't use PHP5 goodies (no autoload, no PDO, no SOAP, no SPL, etc), weird architecture where the controller is also a registry and a factory. A few of what I consider to be downers in CI: the $this->load->lib('somelib') factory scheme; form validation inside the controller; CI Active Record is not a real Active Record, but merely an sql abstraction layer; the newbies to experts ratio in the community is too high (lots of experts don't stick around long enough).

Kohana is a huge improvement over CI nowadays, but it still suffers from a lack of exposure. More often than none, the process through which one joins its community is the same. You're a CI user and you're experiencing an annoyance with it and dare post a complaint in the forum, then someone pm you the name "Kohana" (it is generally preferred to carefully avoid mentioning that name in the CI forums as it has the potential to create turbulences in the otherwise civil discussions). Then when you check out Kohana, it appears to be all that you wished CI would be. Be careful though, Kohana is better than CI, but not quite the ultimate solution yet.

Pros: PHP5 and goodies, a decent Active Record ORM (it's no Propel or Doctrine, but it's quite useful for common CRUD operations). Modular approach (aka HMVC or PAC). Stricter approach to architecture than CI, there is a clear definition of roles for different classes (registry, factories, template view, etc). The code looks good. It's maintained by the community, so development is more active. Developers also seem to care more for best practice. There is an effort to cover some of the most obscure concepts through blog articles.

Cons: Doc is not always consistent, in some areas it will be outdated, while on other it would cover features only accessible from the non-stable svn version. Forum is almost desert, everybody is on IRC. Backward compatibility doesn't seem to be a priority either, not good for a project with such an active development. Kohana doesn't have the sponsor backing that CI has, there are no guarantees that it's not just a fad and will stick around for many years to come.

In conclusion, If I were to choose between these 2 frameworks, my vote would go to Kohana.

mike
but would you pick zend over CI and Kohana?
DFectuoso
@Michael: Thanks a lot for this insightful answer. I'd be very interested in knowing what you think about Zend, Symphony etc.
Ates Goral
Zend is excellent. It has an undeniably steeper learning curve and is probably a bit more engineered than many other frameworks, which has discouraged many php developers to the point of anger. There is heavy usage of design patterns and PHP5 features such as the SPL and autoloader.
mike
I'm still a growing developer and I evaluate frameworks not solely on the basis of the code library, but also according to the quality of its community and how it promotes best practice. I got lots of "aha" moments in Zend, as I was exposed to concepts that were nowhere in sight in other frameworks.
mike
I would not consider people who like to get things done "coding mules". But I would agree to some extent, if you want to get things done, CodeIgniter is a good choice. It's possible that Kohana would help you expand your knowledge and techniques.
pbreitenbach
I don't think you understood that sentence as I intended. It has very little to do with programmers liking to get things done, most do. What I meant is that knowledge is a programmer's best tool, but learning can be a costly process and therefore is an investment only for those who see value in it. Many web shops don't and usually worry more about how fast can code be turned into cash. In such places, programmers are seldom allowed time to revisit their skills or learn better ways. A framework like CI, boasting a light footprint and low learning curve, then appears to be a good solution.
mike
+3  A: 

Personally, I am on CI. I've looked into Kohana as well, but I need a more stable codebase with better docs, and I don't see any of the extra features in Kohana as dealmakers.

Just like everyone else, I would like to see CI migrate to proper PHP5, replace their database abstraction layer with PDO, and add best-practices asset and module handling (there are good packages available for this, though); but beggars can't be choosers, and CodeIgniter is a charm to work with even with those imperfections. Plus, you just can't beat the speed of CI ;)

Anyway, for someone trying to choose between CI and Kohana, I would say: go with what feels right. They're both built on the same principles (and base classes - Kohana was originally built on CI), they're both really fast, lightweight, best-practices MVC frameworks, and allow a great degree of freedom for the developer. As long as you're choosing between two of the best damn PHP frameworks out there, you're not going to go wrong.

Jens Roland
+6  A: 

Kohana has some improvements over CI that convinced me to switch for a new project, besides just PHP 5.

In my opinion, language choice is secondary to platform and framework choice. PHP is a miserable "language", but as a platform you have great choice in deployment and development is made bearable by the various MVC frameworks popping up to give you some structure. The same could be said for Javascript (Prototype, jQuery, MooTools, etc.). Kohana and CodeIgniter are therefore similar frameworks which ease the pain of PHP development and should be compared on that basis.

I'm a former ASP.NET guy and found that Kohana scratched a particular PHP itch for me. Since ASP.NET 2 we've had Master Pages that could contain other Master Pages, which is a really nice way to build a site with a consistent look and feel: you could make a "shell" page and define one or more content areas that you could fill. Naturally I tried to do this with CI, including templates within templates. It is possible, but not very natural. On the other hand, compare this with the very object-oriented template style in Kohana's template controller. Awesome. That's how CI should have done it, but they can't because of the PHP 4 crutch.

Any complains I read about "Kohana's community is smaller than CodeIgniter's" sound like lazy programmers worrying that nobody's going to bail them out if they get stuck. I say: figure it out on your own and post the answer yourself, making Kohana's community better. Pay it forward.

If you're looking for speedy execution, check out the Yii framework. Of course, for raw performance nothing beats raw PHP, but that's always a tradeoff.

Barnabas Kendall
+26  A: 

I have a lot to say for the port and why I'm going to stick with Kohana. First off, the port was very quick. You'll find that Kohana's libraries and helpers are neatly named and that, like in CodeIgniter, you'll probably figure out where to look for something by simply reading the file names.

One of the most important features of Kohana was that your final application is a flattened view of your application, the modules and the system. Each of these folders (application, system, modules/application) have the exact same file structure (config, controllers, models, views, etc.), but as you go up (from system, through modules and finally towards the application) files are replaced based on priority. So you can have a routes.php in your system/config/routes.php but in the end your application/config/routes.php will override it (if one exists). This has powerful implications!

The modules are an incredible feature. Consider your running two applications, simply like a front site and admin. There's a lot of times when the two applications will share the same models or have the same base controller. You can put all of those into a module and have both applications refer to the module. One application could also extend or even overwrite bits from the module.

The auto auto-loading helps you avoid making bad design decisions. I remember I had a problem with CI when I tried to make my own helpers that would extract the page section by parsing the URI segments. Now, I could have depended on the URL helper, but it's a bad decision to have a helper be dependent upon another helper. One way to avoid it would be to auto-load all dependencies, but that just makes for a sloppy solution. So what I had to do to avoid it was to fetch the CI instance and just use the URI class instead and cache the results for that request. No problem with that in Kohana, you just write helper::function and Kohana will make it available for you. That means you can reuse Kohana helpers within your own helpers.

Being strictly OOP is a huge plus. You now have a full design freedom and are able to seamlessly implement any patterns and use the full range of inheritance options. When you switch from CI to Kohana you'll start thinking differently about your design decisions. Imagine you had a dynamic header where you'd always like to set certain data for each controller (like meta keywords, description, author, css files loaded, etc.) I'd previously do it by either having a header controller with lots of setters (HMVC and very very tight coupling) or simply define the data for my header view in the base controller (I'd use an intermediary Config class to set the header, page, menu and footer data). I wanted all my pages to have default headers settings where the behavior can be changed in child controllers. So the neat way to do it, with a Config class, would be to have the class loaded with default values and change those in child controllers like:

$this->config->set_header_data(array('page_title' => 'New title', 'page_robots' => 'nofollow');

In Kohana you can do this without any intermediary classes to force behavior because each view is a self-containing object, so in your base controller you can do something like:

public $header; 
public function __construct() {
    $this->header = new View('header');
    $this->header->page_title = Kohana::config('meta.default_page_title);
    // other default settings
}

And in some child controller:

class Child_Controller extends Base_Controller {
    public function __construct() {
        parent::__construct();
        $this->header->page_title = 'New page title';
    }
}

Like other frameworks, Koahana offers 'vendor' support, that is, it provides you with a very simple guideline on how to structure 3rd party, non-kohana, code and have it available across the system. Usually, this involved hacking CI with your own file structure and somehow imposing those guidelines, or you could have been mess, as most, and just smack them all into your libraries folder (where they'd have no place) and just include them in some CI library. Overall, it's very neat in Kohana.

Kohana defines support for parsing config files. There is no 'routes.php', or 'config.php', etc. in Kohana. They're all config files located under 'config/' in your application, modules or system folder. It's supper easy to create your custom files and access it through Kohana::config('file_name.config_key') (Kohana::config() also supports setting values ((auto-magically create new salts and keys every now and then!!!))). In short, you won't have your config.php including a lot of your custom config files.

Kohana is very dependent on events from it's components. That means it's more used, easier to digest from reading code, easier to digest from reading libraries. You'll be feeling at home in no time.

The debugging is much much easier. Kohana offers two modes, based whether the application is in production or in testing. It's handled by config and is very useful for development. You can use the flag to control things like not sending e-mails while in development, etc. In development you have full access to a complete stack trace and generally the errors are more verbose. The thing I also like about Kohana is that it can be set to explicitly fail on the slightest error in development, for things such as trying to access a variable in a view that hasn't been set.

Finally, exception handling is a lot better in Kohana. You also have a lot of options on how to do custom error handling, but it requires zero or less hacking than CI. You can call set_error_handler() and set_exception_handler() and do custom error handling or you can simply overwrite the kohana_error_page.php in views, have it call other views or other controllers (your custom error controller), do something depending if your live or in development, etc.

I guess the trade offs are that CI has a bigger community and more add-ons developed. EEv2 will be completely based off CI and that gives CI developers a huge advantage.

Essentially, both are very easy. You need about as much the same time to grasp the conventions of CI and Kohana and it's a very fast learning curve. One thing you'll notice about Kohana is that it's as easy to extend and comes packed with more conventions that save even more time and that if you ported your CI application to Kohana that, once it's up and running, you wrote less code, extended less core files and implemented fewer hacks.

kRON
This is an excellent answer! +1
alex
great answer +1!
Mademoiselle Vagin Cul
+3  A: 

I am seriously playing with a move to Kohana because I constantly run into walls with HMVC and the 5.2 redesign does not work for me. CI's idea of only one controller is very limiting and I wanted to find a framework that supported multiple controllers out of the box and not through various addons which I have to hack on myself to get them to work from my needs.

Daniel
I have since moved to Kohana 3 and it is much better that CI in that it is extendable and uses the OOP from PHP 5.2.
Daniel
+3  A: 

Kohana looks very attractive because it purports to solve some of the deficiencies of CodeIgniter (mainly around PHP5). But many developers will begin to miss CodeIgniter's stability, documentation and community.

pbreitenbach
+1  A: 

CI have very limited support of Unicode, for example form_validation simply don't work with unicode under CI.

Alexey
A: 

I'm very surprise to read some posts coming from "experts" in PHP and frameworks... Very very very funny. I think that all people who said prefering Kohana to CI should think before writing. The fact that a framework (we speak about a framework not 2 lines of code) is not stable between to versions would lead to automatically reject it. I'm really fear to consider that. All serious frameworks in the history of digital engineering have been stable in their evolutions. Otherwise software industry and software engineering would not have existed.

Ajax