It’s been a while since I’ve had to build a new site and it was my first opportunity to work with Kohana v3 in a production setting. Here’s the final site for NHP Licensing Solutions – who are a specialist provider of licensing and consultancy services to the Natural Health Product industry in Canada.

It took around 7 days to produce the site from start to finish but this also included setting up the development environment on my PC and ensuring I had everything in place to support this site moving forward. When I have ‘play sites’ I don’t have to worry too much about backing them up or controlling the changes but paid projects require a whole new level of discipline. This means my MySQL databases are dumped and backed up every 4 hours, the whole site is backed up every 24 hours and I also maintain an off-site copy as well. I also wanted to switch from Subversion to Git which was another learning curve.

As for the Kohana specifics though let me go through the design process.

The design itself was a WordPress theme from Theme Forest with stock photography and graphics from Photo Dune and Graphic River. I used the default template controller within Kohana but created views for each page layout type and then created views for the graphical elements and finally the content. Therefore, if I want a full-width page and then use two columns and place a few toggle components in there I just nest the views inside one another and avoid repetition. I could have installed the theme into WordPress but in the end I just hacked the HTML out of a few static pages and worked out how the theme worked.

It took me around 2 days to get the shell of the front page together and split into its various components. Another day and I had the second page completed, along with more elements. Another day and the site content was complete. Kohana didn’t help to deconstruct the WordPress theme into views, it was just a matter of me working out how the theme worked and where to cut-and-paste into my views.

And then the real work in Kohana started. I initially extended the HTML helper to build some small items such as the menus and then backed it all out as I was violating the HMVC model by putting HTML into my extended helper. In the end I just used views although Kostache could have helped at this point. I extended the Template controller to setup my site-wide variables and bind $title, $description and $keywords to the HEAD meta tags for SEO purposes. Every page on the site has different values as per best practice. I also had to extend the Valid controller to add two new validation callbacks; one to check that email addresses added to the newsletter were unique (via the appropriate Model) and another to ensure that the default form values had not been submitted. Easy enough to do with the cascading file system.

My biggest challenge was writing the form handling code which took a day and a half. I cut a few corners by using jQuery and the Forms plugin but I wanted a full solution — it needed to be POSTable, client-side validation tied to the blur events and used Ajax where possible. In the end I got there and the approach looks quite tidy in the code as the error messages have been dumped into the HTML so the onBlur events use the same text as the server-side routine. If this site had more forms I’d probably extend the Forms helper as there’s still a lot of PHP in the form view to coordinate the process.

My final task was to then create a single Model and have new subscribers added to the database — all of which took minutes to achieve.

My last day of work was then spent testing the site, optimizing it and driving up the Page Speed score as far as I could. I also setup a custom error handler for the 404 and 500 error messages using a simple non-template’d view.

My last production Kohana site was v2.3 and it was a painful experience as there were few examples around the Internet to crib from. This time around there were many more examples. Stack Overflow had a lot of good answers, the Kohana v3.2 documentation was much, much better and I also had access to Packt’s Kohana 3.0 Beginner’s Guide that I helped to review. Although I will say in my defence that some of those chapters were not reviewed by me and I think in their desire to get this book out that they cut a few editorial corners. The section on custom error handlers is second-rate compared to the Kohana docs and lysender’s articles and there were so many typos in the first few chapters that I feel for any beginner trying these code samples out and getting nowhere. The most common mistake is that < and > are used when it should be ‘ and ‘. There are also some changes between v3.0 and v3.2 such as the process for using Config that could be confusing.

All-in-all, my experience of using Kohana v3.2 was fantastic and I’m very happy with the final result, as-is my client — my sister-in-law. I don’t normally use Kohana for small sites as I don’t need an overhead for less than 10 pages of content. However, this site was just a starting point as I know news articles, blogs and surveys are all on the business plan.

My next project is to re-engineer the O-Sushi site. It’s currently a single page site but it needs a responsive design as I’ve got around 15% of the visitors using smartphones. I’ll also be using Kohana for this project though as I think it’s easier to use Kohana than doing it in pure PHP, especially as I get logging and error handling for free. I’m also not limited in what I do in the future and how the site continues to grow.

Related posts:

  1. Why/When Should I Use Kohana?
  2. PageLines Platform Pro — Why?
Tagged with:
 

Looking for something?

Use the form below to search the site:


Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...