Kohana PHP Framework

February 24th, 2009 | Tags: , ,

I was just reading this blog entry and it reminds me of why using a framework gives the developer so much more flexibility and better off long term, especially for business information systems where business rules change will be made.  Although comparing using a framework as opposed to an out-of-the-box solution is fairly subjective, I do believe that using a CMS does have its advantage when budget is tight.  However, as a full-time web developer for a company, like myself, using a framework is definitely the way to go.

One framework I’ve began using recently is the Kohana PHP 5 Framework.  It’s a very lightweight framework using the Model-View-Controller (MVC) pattern.  While working with the framework, I’ve found several things that I really liked over several CMS software such as Joomla! and Drupal could not provide (or not that I’ve noticed, at least).  I really like Kohana’s simple ability to allow all your scripts to sit under the public root, and be the core of several applications.

Security-wise, I like how simply it is to keep everything under the public root.  The only thing that sits on the public root is in index.php file and any client files (images, CSS, Javascript, etc.)  If the PHP parser fails and the PHP code is exposed, only the index.php is exposed to the public, and it doesn’t contain anything critical except relative paths to your main application directory, which is inaccessable publically.  Kohana has a core “system” directory, and one more or “application” directories for each of your web application.  With this type of filesystem, they’ve implemented the so-called “cascading filesystem.”  If there is anything not set in your application directory (e.g. configurations, error pages), Kohana automatically aquires those lower in the filesystem chain, with the “system” directory being at the very bottom.

Kohana provides all the abstraction libraries for common use functions, like database access, session management, caching, etc.  Additional modules also such as the Auth module for user authentication makes it simple to create and manage secure passwords and sessions.  Even without a URL rewrite module on your web server, building SEO-link friendly apps should not be an issue.

PHP itself is a very lax scripting language that lets developers do whatever they want, which can have major disadvantages when trying to create organized apps.  Having a framework like Kohana definitely helps keep many things organized.

  1. August 30th, 2009 at 02:34
    Reply | Quote | #1

    Hi Jimmy, such a coincidence that we not just share the same name, same profession and also the same issue with the ntwdblib.dll driver issue 🙂

    I came across your blog pretty much straight after I posted an article on my own blog about the windows mssql drive issue.

    Anyway, about the kohana framework you are using, how are you going with it? I use Zend Framework myself, and will be very interested to see comparisons.

  2. September 1st, 2009 at 23:54
    Reply | Quote | #2

    Hi Jimmy! Sorry for the late reply.
    That is an interesting fact. Though Jimmy Li’s not really my real name (my dev alias), but close enough to my real name. I’m sure you’d be able to find it. 😉

    Kohana is actually the first and really the only PHP framework I’ve delved into somewhat deeply, so it’s hard to compare to others, like Zend. Many says that the Kohana docs are not very good, which is true, but it’s fairly simple to understand. I’ve taken a look at Zend’s before and it looked more complicated.

    Things like Authentication and ORM are okay. I’ve tried it but didn’t really like it much. I generally use only MySQL for web and don’t really need ORM for other database compatibility. I especially like the Cascading Directory system, which is great if you have more than one application that uses Kohana. You can place the Kohana “system” (Kohana core) at the root with the rest of your websites, and within each website directory is your Kohana “application” (application core) directory. Therefore, when you have to upgrade Kohana, you just replace it with the latest “system” directory and all websites will use it. (Of course I test it out before making it production.) Files “cascade” downwards (or upwards?), so if something’s missing in “application” (like a config file), it’ll use the one in “system” by default. And both of the system and application folders sit under the public directory, which is a security plus. Only the index.php and other public files are on the public directory. This is not a out-of-the-box set up of Kohana, but very easy to setup in advance since the index.php has references to the system and application directories that’s easy to modify.

    I guess it’s hard for me to explain other things in details. I mainly use a MVC framework and PHP OOP to keep things organized and only use few of the framework libraries (Database, Session, View) and some helper methods. But so far I’ve been able to keep things really organized, make clean SEO friendly sites, and include additional libraries with no problems (like TCPDF, PHPMailer, etc.).

    If you don’t mind, would you point out some of the things you like about the Zend Framework? (I’m taking a look at your blog now also to kind of get a sense of it.)

    Oh, all this is about the current version, Kohana v2.3.4. v3.0 will be a complete rewrite so I’m not sure how things will be there.

    I really gotta get this blog cleaned up from it’s default WP setup. When I do I’ll add a link to yours. 🙂

  3. September 2nd, 2009 at 23:01
    Reply | Quote | #3

    Hi Jimmy (the evil one)!

    The Kohana cascading idea sounds pretty smart, and surely when they roll out V3, the rewrite will make it better! I might get a copy and have a play when I get a chance.

    I was just like you before I started using Zend, trying to get things organised in my own way, and build up my own utility libraries from here and there (ooo … phpclasses is such a paradise.)

    But I then soon run in to function name collision, and php version compatibility issues … and at the same time I started reading about pattern designs and php best practices.

    So … one day I decided to ditch all my old libraries and start from scratch! That says I picked Zend as my framework.

    Zend gives me a clean core with heaps of features, the ones I like and use heavily are ACL, Auth, Registry, DB (Zend’s PDO abstraction classes, not ORM), 2 step view, action helpers, view helpers and so on so forth …

    The advantage is basically just like Kohana, things are organised well. and the advantage for using Zend is it’s a use-at-will framework, you can use its libraries even in your throw away apps. ie, never need to use phpmailer anyway !

    another massive plus for zend is its integrated phpUnit testing libraries!

    anyway, once you’ve got your blog tidied up, i’ll exchange more ideas with you as we go.