To create a powerful website, secure in PHP, with all the functionalities of modern applications, without reinventing the wheel or spending your life typing code, the best is to use a framework. But which PHP framework to use? Many programmers ask this question.
Before investing in long learning work, the programmer must know if this work of appropriation of the framework is worth undertaking. Here is given some answers and reflections, based on personal tests carried out on different frameworks, as well as on Google trend research statistics.
Google Search Statistics
Research on Google, from 2004 to today, for the 5 frameworks: Laravel, CodeIgniter, Symfony, CakePHP, and Zend Framework. If we look at statistics on a global scale, Laravel is the PHP framework of the moment. The youngest of the PHP group has just passed its elders and its progress does not seem to stop there.
The second framework that is doing well is CodeIgniter. It is surpassed globally by Laravel. While the other frameworks are losing momentum, CodeIgniter is maintained and even continues to progress.
On the other hand, at the level of France, the preferred framework of the French remains largely our Franco-French framework, Symfony. This trend in France and many European countries seem to be established over the long term.
Description Of The Main Frameworks
As we have seen, the best PHP framework is without a doubt Laravel. Its progression in the ranking of Google trend searches is impressive. But what about the mechanics of the leader when peeling his breastplate?
What is found under the hood of the beast is both very interesting and disturbing. A Laravel project is created from composing. It is therefore not possible to unzip an archive to create a project. But once you have composed and installed, creating a Laravel project is a breeze.
Like all frameworks, Laravel is based on an MVC structure (model – view – controller), but with some curiosities. First of all, Laravel is based on static methods (called with: :). This way of working simplifies programming, but somewhat complicates the creation of its classes and methods. The machinery at the heart of the framework is quite complex with a dependency injection system.
Some libraries are borrowed from Symfony (Cocorico). Documentation is a crucial point for learning. It is generally quite well done and in French, but the way of approaching MVC programming in the doc seems to unsuitable for beginners.
The model part has a high level of abstraction, thanks to the Eloquent ORM. With Eloquent, finished Grandpa’s SQL queries. Its level of abstraction is quite close to what is done in Django (Python framework) for those who know. The creation of models can be done on command lines, which brings an undeniable saving of time.
The view part is also efficient, with a blade, a templating system that allows the inheritance of templates, etc. In short, only good things.
Laravel is particularly flexible. You can do absolutely anything you want. In particular, the famous file route.php in which we should put the routes managing the URL can contain almost everything. We could create a complete site using only the route.php file. Another worrying point comes from Laravel’s documentation. The tutorial begins by explaining how to do anything with this famous route.php file.
In conclusion, Laravel is a good framework, efficient, easy, pleasant to use, fast, with a small memory footprint. However, care must be taken not to abuse the freedom offered.
In the second place, CodeIgniter remains a widely used framework and rightly so. It is by far the framework that requires the lowest learning time. In one or two hours of learning to Codeigniter, the beginner already masters the essentials of the framework. It must be said that the documentation of CodeIgniter is exceptionally well done. The framework is one of the fastest of the existing PHP frameworks, with a small memory footprint.
We will criticize CodeIgniter for being a little too verbose. Indeed, it requires a few more lines of code than the others, perhaps because it is closer to raw PHP. The good thing is that integrating your classes or libraries is particularly easy.
There is a basic templating system, much less sophisticated than that of laravel. It still allows you to decompose your page by sending several views to the same page.
If you are new to PHP frameworks, there is no hesitation, CodeIgniter is the one that will require the least amount of effort. It will give you a good introduction to MVC programming.
Symfony 2, the French PHP framework recognized all over the world, again cocorico!!! Heavier and more complex to understand than CodeIgniter or Laravel, it remains a safe bet among PHP frameworks. It is much more restrictive than previous frameworks, but here it is the rigor that is preferred. Symfony is based on the concept of Bundles.
Any web application is a Bundle. You will also need to be able to manipulate namespaces and other such characteristics to master Symfony. Finally, debug mode offers interesting information when creating your web application.
If you want to work with an agency and you master MVC programming, Symfony is probably the framework you need, but it may take a little longer to learn it.
CakePHP has been successful for many years. This framework offers a very good compromise between rigor and flexibility, between large applications and small sites.
The principle of MVC programming is well respected. The framework allows you to create projects of all sizes. Its great versatility is probably its strong point. CakePHP also has a templating system which offers a lot of possibilities, but no inheritance of templates.
If you are looking for rigor without too many constraints and certain versatility, CakePHP is for you.
Yii framework, yes it is, is a fairly original framework that deserves to be said about it. The beginning of the creation of a project is done on the command line. In a few instructions, you are left with a site or blog already ready for use. The tables of the database are created in two strokes of a pot spoon and a scaffolding system makes it easy to add entries to the table. At this point, Yii largely distances all of its competitors.
We are already at the operational site stage while the other frameworks are still coding. But then, if you want to change the appearance of the elements, you have to go into the framework, learn the namespaces, and the structure of Yii. So in the end, we are not exempt from learning the framework.
Why Use a PHP Framework?
It is a question that comes up often and deserves a clear answer. This post aims to encourage you to use a PHP framework, no matter which one, during your PHP developments.
An Organization to Your Project
Whether you work as a team or alone in your garage, a project always needs organization. In this sense, the framework will bring you much more than you imagine:
- logical breakdown of source code
- factorization of common components, code reusability
- adding business layer
- separation of technical / business logic (developers) and presentation logic (designers / integrators)
- maintenance and scalability
In short, so many things that will change the way you design your project.
Reusable Components And Libraries
Although a framework like Symfony 2 positions itself as a conductor rather than a simple aggregate of booksellers, the fact remains that frameworks always come with their share of reusable components. Whether it’s modules, plugins, bundles, or whatever makes you happy, using a framework will make it easier (and encourage) to reuse code from other developers. Time saved on your developments!
An Incentive to Good Practices
This is especially true with versions 2 of the most well-known frameworks (Zend, Symfony, Cake). Until now, everyone coded in their corner, without worrying too much about the others.
For a few years now, the PHP world has been organizing, becoming more professional and developments have become industrialized. With the arrival of PSR and FIG recommendations, the source code becomes standardized. Current PHP frameworks are constantly promoting these good practices to make the code from different frameworks compatible.
These good practices are the guarantor of a code that is readable and understandable by all informed developers. Bend to a minimum; it will bring you well every day.
A Regularly Updated Database
By choosing a framework, we also choose an active community that will detect and correct flaws or gaps in the framework. In a way, we pool development resources. You will benefit from the updates of the framework with a lot of improvements (and new bugs ^^) that they include.
Choose a Web Framework
Since the announcement made by Guido regarding his preference for Django two weeks ago, there has not been a day without articles comparing Python web frameworks or comparing Django to RoR or … in short. It’s interesting because it raises the buzz and these frameworks deserve to be known but the choice of a web framework is very often made thanks to other criteria little mentioned in these comparisons.
The very first point to consider is that a web framework is a tool. The technician’s job is not to understand this tool but to know how to use it. A good web framework is therefore above all a framework that can be forgotten. But beware, the term tool is not representative it is more a toolbox that you have to be able to adapt to your needs. To achieve this, two conditions are necessary:
- good documentation to know and know how to use the tools that are already present in the cash register;
- a box large enough to allow you to extend your range of pre-integrated tools as needed (and it happens always).
Currently, frameworks are spread over a scale from the web application to web publishing. So once again you have to choose according to your needs, the framework best suited to make a blog will certainly not be the same as the one with which you will make your web-2.0-app-de-la-mort-qui-tue. Once your needs have been identified, it is enough to know the various existing solutions to already clear a lot of ground. In theory, you should have 2 or 3 at most.
There now remains a question of the technician’s tastes/skills which is rarely taken into account but which is nevertheless crucial in the course of the project. A skeptical technician is less involved and therefore less efficient. Take a completely random example of choosing between Python and Ruby as programming languages for a framework.
Someone who has coded for 3 years in Ruby will go much faster in the development of their application, even if for the same knowledge it would have been faster in Python (well ok not so random). This is completely normal and if it were not the case only one framework would dominate the current market.
There are boxes where the sales department is the nightmare of the technical department and then … no, it always happens like that ;-). How do we get there?
It’s hard to sell something you don’t know someone who doesn’t know either. Playing the pipe on a technology that everyone is talking about is relatively easy. Discovering and opening a client’s portfolio by evoking a tribal name unknown to their entire IT department is already riskier. If also the only example that we have of development using this web framework has not been realized by the box, we understand better the inertia that technology can have.
Two Other Arguments Are Often Raised:
- the lack of available human resources relating to the language or framework and there it is the snake that bites its tail;
- guarantees in terms of sustainability of the framework, open-source are one but if you are there you already know :-).
In short, a framework will bring you a lot with a relatively minor investment compared to the benefits you will derive from it. So it can only be advised to you to train yourself now in a modern PHP framework.
If you hesitate to train, if you want to enrich the post or plead the cause of anti-frameworks, do not hesitate!