The Definitive Guide to Your Next PHP Framework (Part 1)
In Part 1 of this three-part series, a developer explores the concept of frameworks in a web app, why developers use frameworks, and a few interesting PHP frameworks.
Join the DZone community and get the full member experience.Join For Free
imagine if you could type one simple command on your terminal, and see half of the code required for your new web application already written.
this is the power of using php frameworks!
in this series, i'll review 24 of the best php frameworks that will make your job easier and faster.
let's get started!
writing code is fascinating. writing readable code is even more fascinating. when can you do both? that's when you can program for hours and still feel fresh like when the first coffee of the day starts to kick in.
and i have something that will make you feel that way.
what is a framework?
let's start at the beginning, what is a framework?
by breaking up the word “framework” we get “frame” and “work”.
a frame. think about the frame of a house, a structure in which everything else is built around and any work done will depend on its shape. i can say the same for a photo frame, it defines the structure and any photo inserted has to be the size of the frame.
a framework is simply a predefined skeleton in which you do your work. this is software that provides the basic functionality that can be extended using your code. the advantages of using these functionalities are that they are standardized and reusable.
pretend you have spent the last half-hour trying to find a solution to your problem. by using a standardized service, it is very likely that someone has already run into this issue.
this means that the solution is probably out there on the web.
why use frameworks?
to answer this question, i need to go a little bit deeper on what frameworks do.
every project you work on usually begins with the same process.
if you are like me, you have your checklist on the side of your laptop and a pencil ready to check off each action item you complete that helps to start the development process.
if you do not have something like this, it is very likely you'll miss something important.
frameworks allow you to free your mind from these tasks and focus on the development process rather than the preparatory stage.
why worry about setting up authorizations, sessions, writing code that protects you against cross-site request forgery attacks, and so on, when you can spend more time just doing what you love?
not to mention the time you will save by finding this code ready for use, and as we all know that time is money.
since the first framework came out, the list of features being implemented have increased to a much greater degree.
framework creators now have years and years of experience on their background.
this has made them make improvements on it and use the more up-to-date standards on security, as i have shown above.
and not only that, lots of php framework can be installed via composer. in some other cases, you can even just download the directory from a git repository and it is ready for use.
put in place composer to require third-party packages and resources as a great method to extend your projects and make them more scalable.
the code that the majority of them uses is the php object oriented principle.
they automatically create classes and objects in the background (you will never need to worry about including files again).
they also follow the mvc pattern, by dividing the code into models views and controllers, php frameworks make the code easier to work on and increases the scalability of the project.
another feature common among the majority of php frameworks is the way requests are processed.
the routing system of some of them, in fact, is a piece of art.
it permits redirections and better seo management, creating an seo-friendly url.
when should you use php frameworks?
to answer this, you need to ask yourself some questions about the project you want to build.
what are its needs?
does the framework of your choice cover those needs?
do you have enough skills on the framework to accomplish what you need to do?
when using a framework, you need to realize that this skeleton can weigh quite a bit even though you are yet to get started.
so if you are just building a to-do list to get from your phone next time you go to the grocery store or a simple portfolio page that list your skills on a digital screen, you may not need all this built-in stuff.
they will be a problem and decrease the performance rather than a solution.
a php framework can be useful in many cases but it is not always necessary. if creating your applications will be easy and there are not too many features, then the right choice could be to just do it yourself.
when shouldn't you use it?
using a php framework is not always peaches and dandelions.
there are several downsides that you as a web developer need to understand.
a framework is an external component. it is coded from somebody or a team with its own mindset and objectives.
sometimes, those objectives do not go in the direction you need for your projects.
rasmus lerdorf, the creator of php has spoken several times against them, pointing out all the problems arising from their use.
as said previously, the performance of frameworks is slower than code which you can write by yourself.
that is because they have lots of features that need to please the largest number of developers possible.
this means that frameworks solve different problems by providing a general solution.
you may need to put in just a couple of php functions, instead, you will find yourself with a lot of implementation that you will never use and this slows down the execution of your project.
who should use frameworks?
we have talked about the “when,” now it is time to explain the “who.”
to do that, i will tell a bit about my story.
it was simpler, it was quicker, and there were lots of tutorials and plugins available.
there was angular, vue.js, and react and lots of new things coming out every day that do not use jquery but vanilla js.
the lesson i have learned is to stick with the basics as long as you need. php frameworks often use principles, design patterns, unit tests, containers, migrations, and lots more that a newbie does not understand.
you do not have to be an expert but you must be an experienced php developer.
when you feel you are ready you need to book some time to learn any framework of your choice.
some of them are really easy, while others have a very steep learning curve.
do not give up! it won't make any sense for the first couple of hours, this is normal.
just complete the tutorials, search for an explanation online and everything will beging clicking soon.
now that you understand the basic concepts of using a framework, you are ready to go deep and examine each of them.
it is important that you do read the following chapter after analyzing what problem your application or the website you are going to build needs to solve.
enough with the preface, let’s get started!
agavi was mainly developed by david zulke, but has 20 other contributors on over 60 releases.
agavi is a php framework that was at its best between 2006 and 2009.
it is a fast and lean product that is meant to work on a php 5 environment.
the chief focus is toward a few features giving freedom to you as the developer to shape the project as you prefer.
it can be installed via composer or by downloading the repository from github.
this framework can be used for almost every project but it is advised to use it on long-term projects, with a large codebase.
it is accessible via http protocol, soap, and the commands line.
if you want to adjust an old project, or you just want to try this framework out, agavi still provides a good amount of information and tutorials on its website as well as api docs, faqs, and blog posts.
i interviewed david while writing and he was still really passionate about this framework.
he claimed that agavi still has its users, even though he thinks most of them have modified it heavily over time, or taken some of its core concepts, which have aged pretty well overall, and ported them to some custom solution, e.g. symfony, underneath.
he now maintains the php language support at heroku, so he no longer really uses frameworks or writes big php applications, but instead makes sure his customers can do exactly that!github repository
cakephp is maybe one of the most important php frameworks out there.
it started out in april 2005, created by michal tatarynowicz, a polish developer who first published the project under the mit license and baptized it as cake.
cakephp was taken over at the end of the same year by some other programmer that eventually created the cake software foundation and released version 1.0 in may 2006.
in 2018, after all these years, it is still considered one of the best and is on the top 5 most used php frameworks. it retraces in several ways the characteristics seen in ruby on rails and also uses several design patterns, such as mvc principles, active records, and the paradigm of convention over configuration.
i'd like to linger on this paradigm and explain its power.
after you, as the developer, have learned the few convention rules like call a class in a certain way or to end the name of a foreign field of a table with “_id”, the backend of the framework creates everything by itself.
this means that cake can easily create a complete crud system and relationship in just a few seconds by using the name provided within the database.
i believe that if you want to level up your skills and try an easy framework, this is what you need to start with.
it has several features that can be insidious in the beginning, but, after all, it is quite an easy learning curve.
there is a lot of support from the community, over 7000 stars and 3000+ forks on github, plus forums, and official and unofficial docs.
recently, the people at cakephp have been working as hard as ever, releasing the last version (3.5), officially called red velvet.
this year they are also arranging a conference in nashville, tn.github repository to be continued...
this blog post is part 1 of 3 of the kindle book " the definitive guide to your next php framework ."
the following parts will be published during the next couple of weeks or click the link below to download the full version
Published at DZone with permission of Nico Anastasio. See the original article here.
Opinions expressed by DZone contributors are their own.