by admin on November 23, 2011
Codeigniter was my first PHP framework. Though it works nicely for wide range of app types, slowly I felt uncomfortable in some points. For example, lack of OOP practices, untestable structure etc. (Sorry to say, unit-testing in codeigniter was a horror!) Later, among PHP frameworks, I worked a lot with Zend Framework and a little with Symfony . One day Emran Hasan shared IBuildings article about HMVC which presented Kohana as example HMVC framework. That was the starting, in a few days Kohana took the position of primary PHP framework for me. I built website, Enterprise application, Service layer for SOA and few more apps with Kohana comfortably.
But when framework newbies asks me with which one he should start, need to think twice before suggesting Kohana. The main reason is, it’s documentation was not as rich as Codeigniter or Zend Framework. And there was no book. BTW, Kohana unofficial wiki is a BIG try to help in this issue. Besides, recently Packt has published the first book on Kohana “Kohana 3.0 Beginner’s Guide“. Jason D. Straughan wrote this book for Kohana version 3.x. Few days ago, Snehman Kohli from Packtpub has contacted me and requested for reviewing this book. As a fan of Kohana, I’ve happily accepted. So, here is my view on this book.
The book discussed all major aspects of a generic MVC web application. With “how to do”, it have good explanation of “how it works” about most of the things. As a target of step by step learning, it takes a sample web application that will allow users to create simple profiles, post messages for their friends, and manage their public page. Throughout the book, the reader will build this application by learning the Kohana way of MVC components, Routing, Helpers, Session handling, Modules, Database interaction, Templating etc. Also have details discussion of some important Modules and Helpers like HTML, URL, ORM, Auth, Validation etc.
Lets have an overview and see how topics are organized. In first chapter, as obvious, have discussion about installation and setting up the framework. It has discussed different ways of installation, downloading from web, github etc. But I think, it’s logical to start with the easiest way for beginners and put other alternatives in somewhere in Appendix.
When introducing MVC, some flowchart, graphics could help to explain the workflow more clearly. But the current introduction is somewhat Kohana specific, but good enough to start. Techniques of using simple view, template view, composite views, binding global view variables etc. are shown beautifully. The idea of starting with basic Controller and slowly moving to generalized application controller will help to understand practical OOP practices along with how controllers works. Third chapter has enough example and explanation of Routing and Request object.
In Codeigniter, the helpers were all open functions. But Kohana boxed the in classes as static functions which seems more organized and logical for their purpose. This book talked about helpers generally and showed examples from URL, Date, Arr and some other helpers. Has a chapter for another great power of Kohana, easy and powerful Module system. Along with explaining how modules works, this book has separate chapters for Database, ORM and Auth modules. And I think yes, these modules deserves such focus.
In my view, Database and ORM could be discussed together in one chapter. Because of importance, Image and Message module also could be described with some example. Though Message module is used in showing Form errors, it deserves more space. The book explained common security issues and Kohana way of protecting them in deployment chapter. Some of those could be explained earlier in appropriate context. For example, SQL injection could be discussed in “Interacting with the Database” chapter.
Okey, now lets talk about some friendly complains. The form validation is discussed, and it’s good enough. But another good example of handling ajax submitted forms and their validation could make it complete. Though easy i18n is a good feature of Kohana, it didn’t get any focus at all. When I was switching to Kohana as my promary PHP framework, one big inspiration was it’s testability. PHPUnit fits with Kohana beautifully through UnitTest module. But this book have no recommendation or inspiration for testing anywhere.
Before starting to learn something, many people like me, likes to see what most I can do from learning this thing. It can be a demo or some screenshot. Though the author ignored the presentation of sample app in screenshots, I think it’s also important. A beautiful interface could give more impression and inspiration to the learner.
In chapter 8, Error Handling and trouble shooting, examples are shown using Kohana::debug, Kohana::debug_source. You won’t find those methods in newer version of Kohana. Debugging related functions are moved to a new Helper named Debug. So you have to use Debug::dump(), Debud::path() etc. In profiling section, I was expecting some initial talk about manual profiling along with Kohana default benchmarks. There was some minor printing issues, but can be problematic for beginners. For example, in many places, single quots(‘) changed to ‹ and › characters.
Overall, the book is well organized, focused and will be helpful on it’s purpose. I felt it’s capable to teach Kohana to a new guy, in a smooth way. Yes, there have some printing mistakes, old (because they are changed in new version) function use and some other minor issues, but seems ignorable to me. I’d recommend it for Kohana beginners. A little experience with CodeIgniter or other MVC framework can make the learning faster. But if you don’t have, don’t worry, just start from here.