Yii2 vs Laravel 5 - Rapid Application Development in PHP

Yii2 vs Laravel 5 - Rapid Application Development in PHP

By Daniel
- Updated 7 years ago
5 comments

Some background

I used to be professional web developer before dedicating myself to Environmental Engineering. Nowadays I only develop applications for very specific engineering and scientific purposes. Since I have an average of one project per year, I can give myself the time to research and learn about the recent platforms and best practices for those projects.


My experience with PHP applications development started before the year 2000. At that time, we had a very limited set of functions in the PHP core and the discussions in the Forums were around the best ways to authenticate a user, store cookies and save passwords in databases. A lot happened in the last 15 years, programmers realized that most of their applications looked the same in terms of coding and started to provide functional plug-and-play libraries known as modules. PHP modules were then combined with theories of application organization (aka "MVC") and the "Frameworks" emerged.


Since frameworks are quite recent and most of the PHP programmers were already used to do the things in their own way, many decided to create their own platform based in their own personal beliefs. This combined with social networks activism lead us to the "Best PHP Frameworks in the World" nightmare.


Living in this nightmare I had the chance to develop applications using CodeIgniter (1.x), CakePHP, Laravel and Yii. This article represents my opinion between the two "trendy" frameworks for the specific scope below. It took me about 3 months to deeply understand their weakness and strengths and this article was focused in how they could help me to get my objective applications done quickly.

What my PHP web applications normally do

  • Standard straightforward user interface with a frontend and a backend. No fancy HTML designs here.
  • Authenticate the users and enable features according to the groups/roles they belong.
  • Allow the users to browse, add, edit and delete data from a database (CRUD).
  • Generate some user customizable reports.
  • Generate some customizable graphics based in the stored data.
  • Export/Import data to Excel spreadsheets and/or CSV tables.
  • Display non-editable/read-only contents in the frontend.
  • Get and process data from very specific external sources using third party APIs.

What I expect from a PHP Framework

  • Login and permissions/roles system out from the box compatible with the best security practices.
  • Rapid prototyping: Automatic generation of the boilerplate for CRUD (Create Read Update and Delete) operations from an existing table or database schema.
  • Rapid prototyping: Automatic generation of Forms and Views for the CRUD operations. I will later customize this code but I need something to check if my models and controller logic are OK before going deeper.
  • Plug and Play AJAX based CRUD operations (REST, RESTFUL...) that could be used with client side JavaScript interfaces.
  • Some logging for user actions and system errors.
  • Some statistics.
  • Helpers for: dropdown lists, search boxes, pagination, table ordering, printing and data exportation.
  • Some basic CSS and Javascript code for the boilerplate pages (I don't like Bootstrap look but that's nice for the beginning).
  • Minimum external packages dependency for the operations above.
  • Option to NOT USE super automated dependency repositories and build tools (Composer, Bower, NPM, Grunt, etc...).

Laravel 5

Strenghts

  • Concise core system with well written and very intuitive components.
  • Many activists all around the internet.
  • Uses proven components from very traditional frameworks (ex. Symphony).
  • Latest PHP programming practices and versions are always incorporated in new versions.
  • Excellent performance (without 3rd party extensions).
  • Native cloud/file handling modules.

Weakness

  • No continuity between versions. Update the core for the version 4 to the version 5 and your application will break.
  • Artisan auto-generators are too basic. You will get much faster results by coping and pasting existing code from other projects since the make commands only build skeletons.
  • No standard/development views generation. You will spend hours coding before being able to test your application outputs.
  • No authorization/ACL/roles features included in the official distribution (what is authentication without hierarchy?).
  • Default authentication system is incomplete and requires manual implementation of basic features.
  • No HTML or form helpers in the official distribution. All HTML and the respective PHP backend coding must be done manually
  • Most of the extension packages available don't make use of native Laravel components. The result is an application with a lot of code redundancy. In fact, most of the extensions are framework agnostic pieces of software that could work wherever you want.
  • Most of the extensions lack documentation and won't run out of the box. You'll find yourself reading a dozen times the GitHub's README.MD files and will spend many hours solving all the errors and incompatibilities that will be presented.
  • Most of the packages use a bunch of build tools and dependency managers. It's almost impossible to keep track of the updates and changes in the packages and sub-packages. If using development versions frequently some features might break from one update to the other.
  • Laracasts: Not everyone prefers to watch videos instead of reading a well documented guide.
  • Confusing folder organization.

Yii 2

Strengths

  • Can be installed by downloading a zip package, no composer or other package managers required (you can use them as well).
  • Out-of-the-box CRUD generation with functional views, controllers, search functions, models, etc...
  • Out-of-the-box user authentication with ACL/roles and permission modules.
  • Official standard site boilerplate with user authentication and Bootstrap views. With a few more clicks you can also have a CRUD interface right from your tables.
  • Intuitive folder organization.
  • Custom widgets for functional PHP/HTML snippets. Very useful while building dashboards.
  • Built-in widgets that render data tables as plain HTML or using AJAX dynamic views.
  • Bootstrap and JQueryUI widgets. Create a working page menu without external modules.
  • HTML helpers to generate tags and form components from your code.
  • Debug toolbar for displaying technical data and statistics during the code execution.
  • Powerful internationalization and translation tools for multi-language applications.
  • Excellent and very detailed official documentation.
  • Centralized information resources in the official website.
  • Mature development cycle. No extravagant or revolutionary changes every 6 months.

Weakness

  • Less user contributed extensions than Laravel.
  • Less commercial extensions than Laravel.
  • Coding looks more polluted because of the extensive use of PHP arrays instead of single object properties.
  • Different configuration files for different environments can be quite confusing.
  • Version 2 is still too new and most tutorials, documentations and extensions will take a while to be updated.

Personal veredict

Laravel, according to their own website is a framework for artisans and we all know artisans look for the perfection instead of an average or "good enough" solution. During my use of this framework I found myself trying to find the perfect modules for a perfect integration and elegant solutions for all my problems. Unfortunately that takes time, a lot of time, mainly because you have to learn and integrate each one of the extensions as if they were a new framework. Laravel developers got rid of very important key modules for a web application relying on third parties. This could be one of their positive aspects but became their largest weakness. Many (to not say most) of the extension suppliers didn't followed Laravel philosophy and came with ugly, messy and buggy codes, a lot of redundancy and sometimes very serious security flaws. Those extensions were fixed and modified by the users and generated thousands of forks and variations. Nowadays the extensions and modules are so dispersed that finding the right piece of code might be more difficult than coding a complete new solution from scratch, that kills the main benefits of the frameworks (saving time).


Yii2 is a All-in-on out-of-the-box solution. Yii takes into consideration that a web application is not only made of PHP scripts but also HTML and JavaScript and handles them all. Unzip a package and have a simple web application operational in a few minutes or hours with the Gii generators and the standard site templates. Working on an already functional code makes the development faster than ever. If you need some common usage features (like a pop-down menu or an authorization model) they will be there, ready for you. No extensions required neither new coding practices learning curves. The single resources center (Yii website) and the centralized development really help in terms of finding what you need faster and keeps all features and codes in the same tracks and standards. Of course maintaining all those features working in harmony takes a lot of efforts so the developers can't make significant upgrades or changes too often. What I really love on Yii2 is that the security features (authentication, authorization and other protections) are integrated in the core code, this is very important especially for larger enterprise services.

Tags

Comments

I had the experience of working with F3 v2 (had a serious injection risk in its template engine). Also I had the experience of ASP.Net 3.5 framework. I started Yii1.1 in 2012 and it was really excellent (however had some bugs in jquery, previously I was experienced in jQuery too) next in Yii2 with a rational set of changes for migration they kept their way as excellent. But ALWAYS there was a weakness : huge and heavy AR (ActiveRecords and ORM) I can't rely on it however Yii1 and 2 have excellent model and component classes for extending but particularly AR is weak. AR ORM is not only useful for DBMS independency but even when you have your criteria of RELATIONs in your own models you will have a less buggy code (each relation code is defined in one root model code only not spread through the db codes).

But the AR weaknesses is not only about being heavy, we have bugs too for example Yii2 currently AR joinWith actually is not working as it must be (described in my git pull) because you have still two queries with their schema query instead of just one single join query. It is due to assigning values to the "withed" relative :) sub-model because the ambiguous column names can't be distinguished during join but you know it is easy to make aliases in the query builder layer automatically to solve the problem. Another weakness was about not respecting to the sort of our joins. We may want to filter a set of rows using a tmp innerjoin before making a huge other join but AR will not respect it :

SELECT * FROM x

INNER JOIN (SELECT 1) AS tmp ON x.ISO="asd" --I need this line to stay here because it is faster than puting in the WHERE clause at the end 10+10 < 10*10

LEFT JOIN y ON y.ID=x.yID

Also this style of query optimization is not respected in the framework itself forces me to be after a solution such as doctrine-orm independently. Fortunately Yii2 authentication and filters layer(my handled authorization for special cases) easily can be used with other types of ORMs (not limited to Yii AR), TnxFSM  because AR traits are so huge and useless in many cases.

At the end I can say Laravel is similar to F3 but I always was worry about the performance benchmark of Yii2 vs Laravel5 in real busy situations... however many people tells us Yii2 is lighter.

Submitted by Igor Kuna on Thu, 12/29/2016 Permalink

I have about 4 months of experience with Laravel and have just shifted to YII2 for our new project. The out-of-the-box solutions it provides are really amazing.

Submitted by Jamie Robe on Thu, 12/08/2016 Permalink

I wanted to say that your comparison of yii2 and Laravel are very helpful. I am an engineer and I could appreciate everyone of the things you were looking for. I am close to moving onto yii, but have been tempted by the Laravel videos. But I am reading how yii is more out of the box. Peace, Jamie