PHP Frameworks have been receiving a lot of attention in the past few years from the web development community. What’s this hype all about?
If you look at PHP Job listings, you will often see “MVC Framework Experience” as one of their requirements. It is becoming one of those must-have skill sets for web developers.
There are pretty good reasons behind all of this. In this article we will explore why you, as a PHP programmer, should be using a PHP Framework.
Code File Organisation
php-framework-codeigniter-directory-structureJust because you created an “/inc” folder and made a “functions.php” file does not mean your code is organised.
When you setup a PHP Framework, it already has a certain folder structure. It is expected from you to follow the same standards and keep everything organised in a certain way.
Once you get used to this model, you will never want to go back.
Unfortunately for some command line champions that still use vi, this can be a challenge. You will need to work with more files, that are smaller in size. But when you use a decent modern code editor or an IDE, it will be a breeze to browse through your application code and find what you need, quickly.
Utilities and Libraries
PHP is a great language for web development and provides countless number of tools and libraries.
However, if you ever try to build a whole website with PHP alone, you will find yourself either hunting down a lot of 3rd party code and libraries, or have to write them yourself.
All top PHP frameworks come with certain Libraries and Helpers, that help you with:
Session and Cookie Handling
Email, Calendar, Pagination etc…
The list goes on. Not to mention, there is plenty of plugins provided by the community that you can add to your framework.
PHP itself works like a template engine. However, when used irresponsibly, it leads to very ugly and unmaintainable code.
The way the MVC Pattern applies to PHP applications:
Models represent your data structures, usually by interfacing with the database.
Views contain page templates and output.
Controllers handle page requests and bind everything together.
This kind of separation leads to cleaner and more maintainable code.
Less Code & Faster Development
There is of course a learning curve for all PHP Frameworks. But once you get over this hump, you will enjoy the benefits of rapid application development.
You will write less code, which means less time spent typing. You will not have to chase down 3rd party libraries all the time for every new project because most of them will come with the default framework install.
Also, since you are being more organised, it will be much faster to chase down bugs, maintain code, and make changes to existing code.
All popular PHP Frameworks have great active communities behind them. You can talk to other developers, get help, feedback and also give back to the community yourself.