I thought I would share with you my experience of PHP frameworks, and in particular a framework called CodeIgniter which I have been using a lot recently. A PHP framework is a platform which enables developers to quickly build web applications without having to re-invent the wheel every time they want to, for example, insert data securely in to a database. This article looks at CodeIgniter (http://codeigniter.com), an open-source PHP framework which in my opinion is fantastic.

The need for a framework

I am an English web developer who has been in the business for over 10 years. I started my business when I was just 17 and started coding in PHP when I was 21. I built my first PHP web application, which was a search engine for musicians, completely from scratch in 2003. It has since become a major success and I still proud of it, though when I look at the code I would love to re-build it knowing what I know today.

After working for many clients and after looking to try to develop my own ideas I soon realised that I was spending a lot of time re-producing the same code snippets on different sites. For example, by 2004-2005 I had written my own database interaction class as well as other functions which made life a lot easier when building websites, for example a function that formatted dates nicely.

This effectively was my own framework, but it suffered from not being very well organised and not very efficient. What I really needed was a tidy way of structuring my code, for example being able to separate my database interaction files from my view files which just dealt with logic (if statements) and the HTML. I had to wait a few years for the right solution.

Making those little ideas become a reality

I often get ideas for websites, some crazy and some simple. Most of them got written down and forgotten about because of the time required to build the ideas in to fully functioning websites. That was all until I discovered CodeIgniter in 2008. CodeIgniter in their own words: “is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications. If you’re a developer who lives in the real world of shared hosting accounts and clients with deadlines, and if you’re tired of ponderously large and thoroughly undocumented frameworks.”
In other words it’s a solution that provides most of, if not all of the tools you need to build your ideas in to websites. After downloading CodeIgniter, looking at their demo tutorials and actually having a play with it myself, I was very impressed indeed and realised I could make my ideas become a reality in very little time.

What about the other frameworks?

Before I jump in to my own opinions about how wonderful CodeIgniter is, let’s take a moment to explore the other frameworks out there. I am aware that there will be developers reading this who do not share my views and believe that the framework they use is best for them. I need to just point out that my findings and experiences of the different PHP frameworks have lead me to believe that CodeIgniter is best for me in my situation, but might not necessarily be the best for you in your situation.

Other PHP frameworks I have come across are:

Symfony is a very powerful framework with functions for practically everything. I worked at an agency that used this framework and though I delved into it a little bit, I never fully could understand it (also the manual for Symfony was very big and heavy!). However it was just right for the website that it powered and I know that a lot of big and well known websites use Symfony. Symfony isn’t that easy to install and does have a steep learning curve.

CakePHP, as far as I’m aware is very similar to CodeIgniter, so is easy to install and well documented. I have to say I haven’t tried CakePHP but would recommend you look also at this open-source framework as well as CodeIgniter if you want to make some comparisons between the two.

Zend in their own words, “is based on simplicity, object-oriented best practices, corporate friendly licensing, and a rigorously tested agile codebase”. Zend is rather complicated and expects you to know quite a bit about coding, so is perfect for people who understood the previous sentence. Howerful Zend is also very powerful, widely used and supported by a large community.

Take also a look at this post: Best PHP Frameworks to build quickly complex web applications

Designers who are also developers

I don’t claim to be a hardcore PHP programmer and know plenty of programmers who are total experts in PHP. I would say that I’m more of a designer who became a developer. As a result of that I sometimes struggle trying to understand something like Zend or Symfony, as you found out above. What I needed was a framework that really explained everything clearly to me, was built specifically for people like me but also had a large community of users in the same boat as me.

I found CodeIgniter had all of these things. The minute I first landed on their website I knew that they had designed their framework with people like me in mind. After downloading and playing with CodeIgniter on my local machine I began to read their documentation and was worried that was where it would all end, but instead I found the documentation on their website really easy to understand and very clearly laid out.

I had soon built an idea that had been running around in my head in to a fully functional website, with user login, avatar upload, questions and answers submission and a very basic CMS. I built that entire website in a weekend, thanks to CodeIgniter. Every time I got stuck I simply searched the community forums, or asked a question and got a response very quickly, and that was only when I couldn’t find the answer I was looking for in the documentation, which was quite a rare occurence.

Tidy code makes all the difference

Tidy code, but also code you can re-use makes all the difference. CodeIgniter uses something called “MVC” which stands for “Model – View – Controller”. The idea behind this is you can separate your database functions (”model”), from your view files which contain your HTML (”view”), and link the two together (”controller”).

By using this practice your code is tidy and re-usable. For example, when building my questions & answers website I could simply just copy and paste the database call which selected all my users, rename the table name in a single line of code, then I would instantly have another function which selected all the questions. By using their “Active Record” class, you can easily put a ‘where statement’ in which only selects records from a certain category, for example.

After building one of my ideas in an entire website in just 3 days, I quickly found my dusty book of other old ideas and realised I could build these in to websites in very little time. How exciting!

Just have fun!

I suggest you download CodeIgniter, install it and have a play. Even if you don’t know much about PHP or programming I can guarantee that you will soon pick up enough of the basics that you will have a basic blog up and running in very little time, providing you follow their tutorials and documentation carefully.

Who knows, you might even end up putting your PHP developer that you hire in at a very expensive rate out of a job! Then again, if we all stick to what we are really good at doing, maybe not – but you can still have a lot of fun trying!