Symfony vs mvc

In modern Programming, package and libraries are not enough for an enterprise level software development; programmers need to be armed with frameworks because they provide broader range of tools than packages and libraries. Although Frameworks have commonalities like providing the structure for the software developer or assisting programmer to do routine tasks, they have still significant differences. The goal of this article is to compare two web development frameworks and their ORM from a development point of view: ASP.Net MVC and Entity Framework (.NET and C#) vs. Symfony and Doctrine (PHP). A comprehensive comparison of these frameworks not just helps you to better understand these frameworks but also help you to decide which language and framework is suitable for your needs. Also those looking for PHP vs ASP.NET MVC comparison may find this article helpful although PHP vs ASP.NET makes more sense since ASP.NET MVC is a framework while PHP is a language.  

Symfony vs mvc from ORM Perspective

ASP.Net MVC uses Entity Framework (EF) as ORM and Symfony uses Doctrine. Both EF and Doctrine can map models to database tables using a configuration. Both also can generate Classes from already existed database tables. EF has a third way method naming Code First to do so which is lacking in doctrine. Doctrine uses YAML files for mapping Classes to tables and EF uses .dbml classes to achieve same purpose. YAML syntax is very easy to learn and for a professional programmer is faster to develop however EF provides Wizard facility which is easier for novice programmers. For data initializations EF provides code based method which is to code the data as objects or loading a .sql script file. Doctrine however uses fixture files which are again in yml format. Again for a professional programmer handling .yml files are faster. From engineering perspective config files like yml and xml with easy to learn structures are easier to maintain and handle. As a case, a developer can build a web interface to create and manage Models in Doctrine a lot easier than EF because in Doctrine you just need to update a file and perhaps run a script to read the file again and build model and tables.

Code structure in Symfony vs mvc

Code structure in Symfony is more divided in parts than ASP.Net MVC. You have Applications, Modules and Plugins in Symfony where each of these can manage their models, views and controllers independently while in ASP.Net MVC you just have Areas to achieve the same purpose. Although this may seem unimportant in small projects, the need of integration and unity of whole system makes these provided solutions vital for enterprise level projects. Symfony in addition to the package structure has more code Fragments than ASP.NET MVC (Code Fragments are pieces of code that are smaller than a whole model, view and controller and have only a portion of all). In Symfony you have the option to use Components, Slots and Partials whereas in ASP.Net MVC you just have partials and Sections. Partials are the same in both. Using components you can fill a section of a template by fetching a Data in a DB and passing it to a partial view. You can achieve the same thing in ASP.Net MVC using Html.Action() extension method. The difference is that the action you call in Component of Symfony cannot be called from Internet like other actions and is faster. Slots are portions of a layout or template where they can have a default value but every action can also fill them too. This also can be done in ASP.NET MVC using section; the difference is that section can be filled in View and having default value for them is a little more complex. One important point to note is that the flexibility of Symfony to have this varied range of options inherits from Dynamic Binding feature of PHP and the fact that this language is Interpreter-based.

Symfony's Code Generator vs mvc's Code Generator

One powerful feature of Frameworks and especially Web Platform Frameworks is their underlying code generators. Both Symfony and ASP.NET MVC have code generators. Symfony’s is implemented via Tasks and called through “php symfony …” command and that of ASP.NET MVC is Scaffolding and either invoked through wizard or called through Power Shell. Both of these code generators have ability to be overridden. Scaffolding is the code generation feature of .Net and the method to write custom scaffolding is pretty much the same for all .Net projects. If you are interested you can read this article of mine. Symfony’s Task feature is a powerful tool and allow you to override or extend Tasks in every Package level I mentioned. This means you can have a custom Task (code generator) for a Project or a Plugin. In .Net you can have custom scaffolding for just a Project.


Forms' UI controls comparison of Symfony vs mvc 

Symfony and ASP.NET MVC have completely different attitudes toward handling forms. Symfony sees a form as an object, containing a number of Widgets (UI controls or from an ASP developer’s point of view EditorTemplate) and validators for those Widgets. ASP.NET MVC sees a form just like any other Views. ASP.NET MVC does not bind a validator to a Form, but to the Model. Personally I believe Symfony method is more structured and standard-compliant because a form defines the type of a UI control and the validation not the model itself. You may want use a Multi-select UI for a field at a form and a Checkbox List at the other. You may want to activate strip-script validation for a form and deactivate for the other. What I want to say is that with the OOP feature of defining a form in Symfony you can manipulate a form easily but in ASP.NET MVC you should use “IF-Structure” or worst copy-paste and edit the form to apply your modification.

Configuration and maintainability in Symfony vs mvc 

Symfony manages all of his configurations through yml file while ASP.NET MVC uses a mixture of xml(web.config) and code. For example Symfony handles its routing through yml files while ASP.NET MVC uses Class files and c# code to handle its routing. Routing is not the only instance, authentication and authorization is another one that the file-management feature of Symfony allows you to manipulate the Role Management completely. In ASP.NET MVC however you should change the filter parameters above an action (Membership and ASP.NET Identity) and recompile. As you may note Symfony is more maintainable. For example as once mentioned you can develop web interfaces to manage all configurations while in ASP.NET MVC case you need to change the code and recompile. One great feature of Symfony is its admin generator which it allows you to create a Grid-Oriented management of a model in literally one hour. Again such Admin page can be created using an yml file.

Read 4618 times Last modified on Sunday, 23 August 2015 15:14
Rate this item
(1 Vote)
About Author
Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

Advanced Programming Concepts
News Letter

Subscribe our Email News Letter to get Instant Update at anytime