These days, everyone is trying to do things faster and more efficiently and the same principles apply to PHP development. And if you’ve ever looked into speeding up your PHP development or application you may have come across PHP frameworks. Yet, with all of the options and information about frameworks floating around the web, you may be confused about exactly what they are and how they can benefit you. We’ll try to layout a super simple, easy to understand overview of what they are and why it maybe something you require on your next job.
The first thing to know about frameworks is that the majority of them apply the MVC concept. I know…I know, another acronym. MVC stands for Model, View & Controller. Here’s an overview:
Picture three different folders in your head. Each are named Model, View and Controller. All of our ‘model’ files will go in to the Model folder, ‘view’ files in to the View folder and ‘controller’ files in to the Controller folder. The view files handle what is being displayed to the end user. The best way to describe model files is if you pretend they’re a link in a chain. They typically handle database queries and controllers control them, and view files utilize them. Controller files are the brains of the operation. These files will typically contain various functions which can be called by model files.
Confused yet? Don’t be. Let’s try this explanation. Let’s say we have ABCXYZ blog site. This site is not using a framework. It’s coded in traditional PHP. Our “users” page is called users.php and contains several functions, sql queries and of course quite a bit of HTML for output on to the screen.
Well, what if I told you that by using a framework that one file would be chopped in to let’s say three separate files. Users.php (controller), users_model.php (model) and users_view.php (view). And by doing this you could increase the overall performance of your site and…yes AND if your coder is fluent in using frameworks have the site built in half the time.
Now I have your attention right?
The advantage to the coder is frameworks such as CodeIgniter have built in functions and shortcuts which help us save a heck of a lot of time while using functions which are completely optimized to begin with. The advantage for the end user is instead of having all this PHP one on file and it all being loaded, only certain portions are loaded depending on the request of the user. In the end, this provides you with a very lightweight and fast application.
PHP frameworks are not for every application though. The best example I can give you is our latest WordPress plugin we released. It is coded in traditional PHP/HTML as using a framework was not practical, especially with the built in shortcuts in WordPress.
We use the PHP Framework, CodeIgniter for some of our larger applications and it has become our framework of choice.
Stay tuned for more in-depth coverage on Frameworks and more!