Shortly after programming was invented, it was noticed that it involved many repetitive operations. And maybe shortly after that, Ada Lovelace—spanner in hand adjusting Babbage's differential engine—or Alan Turing at Bletchley Park decided to modularize code. So, you only had to write certain chunks once, and could then reuse them. PHP programmers are used to writing separate chunks of code in functions, and then storing those functions in include
files.
At one level, a framework is just that—lot of chunks of code stored in separate files, which simplify the coding of repetitive operations. In the previous examples, connecting to the database or building HTML form elements are abstracted and simplified for you. You call a function in the framework, which is easy to handle than the original code.
It goes beyond that. Writing code involves continuous choices between the many ways of tackling the same problem. Most frameworks impose a set of choices on you. They've started to handle the problem one way, so you have to go that way as well. If they are sensible choices, it makes your life much simpler. If not, it's like trying to write a sales brochure using Excel, or showing cash flow projections using Word. Both can probably be done, but neither is the best use of your time.
Sensible design decisions make sure that the things you need are accessible, but prevent them from spilling over into each other. A good framework makes these decisions for you—starting off with a sensible foundation for your program and guiding you through the next steps.
A framework will also improve team programming. As every developer has to adhere to the framework syntax and structure, it is an important part of software maintainability. The code you write today needs to be readable by other people in future. Imagine you arrive to a new workplace and then you inherit a couple of projects. In a perfect world those projects would be well commented, but reality usually hits... Wouldn't it be nice to have a central resource of documentation to get started with those projects?
Most frameworks will offer good documentation. CI isn't an exception; everything is well documented—functions, structures, conventions. You won't have to imagine what a certain function does, you will know it. A very good starting point, don't you think?
Nowadays there are lot of frameworks out there, not only PHP frameworks but Ruby frameworks, Python frameworks, and so on. For PHP programmers there are hundreds of options (well, may not be hundreds, but if we do search for PHP frameworks the results will be overwhelming). Of all these options there are some that are more popular; CI is among them, with others such as CakePHP, Zend Framework, Symfony, and more.
As you are reading this book, you are interested in PHP frameworks, especially CodeIgniter, so we will keep to it.
If you take a look at http://phpframeworks.com/ and http://www.phpframeworks.com/top-10-php-frameworks/, you will see how well CodeIgniter is doing. CI is very popular as a PHP framework; with this book you will know, why. Also if you look at some forums and blogs you'll notice that postings get very heated about which framework is the best. The truth seems to be that each has its strengths, and none is without its own weaknesses. In time you will learn to decide which framework to use in which project. It is recommended that you should think about which tool to use, before starting your projects. Choose the one that will help you to end with a well done project, in good time, and with the best possible scalability. Most of the times CI helps achieve this.