Five months with Symfony 2

Hi folks,

Well, today I am going to briefly discuss on couple of things which I have learned throughout my journey in Symfony 2. ย Well the journey is still ongoing and this brief discussion is about first couple of months, in exact terms first five months.

At very beginning, as an experienced CodeIgnitor and CakePHP developer, I found that Symfony 2 is quite confusing for me. The bundle concept started to bring some nightmares on me. The ‘bundle’ concept is a whole new experience for a developer who is sound with PHP frameworks such as CodeIgnitor and CakePHP. But today I found that, I am so lucky to get my self around with ‘bundles’, which makes developers life very straightforward and easy. I honestly believe Symfony 2, SensioLabs, Fabien did the correct thing by introducing ‘bundles’ for Symfony 2 which was not there for Symfony 1.x versions. Bundles let you organise your features, functions within your project in most efficient manner. The knowledge of arranging your projects according to functions, features within bundles will come to you once you spend sometime playing with Symfony 2. Then you come to a point, you get a feeling that how the things should get arranged in terms of Symfony 2, bundles point of view. So try your self by playing with Symfony 2, creating bundles under various vendors, etc, try your self how the bundle is created.

Firstly, I did not agree with the concept that MVC structure should reside in a bundle. In other words, you will get the whole (most of) MVC structure inside a single bundle, but obviously not in a same location, in their own respective places, inside bundles. But after few weeks I realised that I was wrong. Bundles help you to understand and focus on certain areas of a massive project in effective manner. That’s the reason we bundle certain things together at first place. As developers, we know how hard it is to manage more than one thing at a given time. Imagine we are dealing with a piece of code, which has a dependency on something, which reside on a totally different place in the project, altering that piece of code leads to huge problems by the parties which extends that. These things are common for developers aren’t they? But within a (proper) bundle structure you reduce lots of chances with messing up the code. That is the beauty of bundles in Symfony 2.

Once you are familiar with bundles concept you are actually ready to go. But certainly there are many concepts to be learned throughout the journey of Symfony 2. I was never a fan of console commands until I realize the powerfulness of Symfony 2 commands. Basically, you can do lots of, I repeat lots of things using handy little console commands. You can import the whole database including relationship among tables (excluding few things such as bi-directional relationships, life cycle call backs, etc) in any given format (PHP, XML or YAML) in no time thankful to Symfony 2 console commands. Not only that, you can generate entities for each imported file (we call it ORM files, which will be talking next), even forms for each and every entity, clear cache, create bundles, tables, etc.. in no time. Imagine you have created a table called ‘Contacts‘ and you are planning to perform CRUD operations to this tables. Telling Symfony 2 about this newly created table is very very easy. It will create the foundation for interacting with this new table (we call it entity in Symfony 2) thankful to it’s handy console commands. So if you are learning Symfony 2, never ever miss the beauty of provided console commands.

When it comes to communicating with the databases, we cannot forget Doctrine. Doctrine (version 2) is a very powerful and handy object relation mapper (ORM) which is shipped with Symfony 2. So in your time with Symfony 2, you will get the golden opportunity to learn this handy orm. Don’t miss it. With the help of Doctrine you reduce lots of stress specially when it comes to dealing with more than one database platforms. Because of ORM’s database independent behaviour (one of the main job of an orm), you don’t want to worry if your database changes from MS-SQL to MySQL or to Oracle and so forth. Lot’s of database stress will be taken care by this powerful and handy orm. So inside your Symfony 2 project you will write platform independent doctrine query language (DQL) in contrast to structured query language. Trust me, learning DQL is really really cool. At the beginning you will find it little difficult to get your self around that. So that’s why you should read their document top to bottom. It’s interesting. By the way you don’t have to worry about the installation part of Doctrine 2, as it is already shipped with Symfony 2 by default.

Another beautiful thing I learned thankful to Symfony 2 is the TWIG. Twig is a powerful and smart templating engine, which is brought to you by the same development team of Symfony 2. Twig and Doctrine 2 is like the better half of Symfony 2. Twig helps you to render things nicely and cleanly. It’s bit tricky though. Because there is a Twig specific syntaxes you will need to learn (thankfully we have a nice documentation in their website) in order to harvest the maximum out of it. But once you get your self familiar with Twig and it’s syntaxes, designing user interfaces will become a joyful thing. The best thing I noticed in Twig is, it’s conciseness of both syntaxes and concept it self. You can do lots of UI things in Twig in no time.

So, my journey in Symfony 2 never ends, as it’s one of the coolest PHP frameworks to learn if you are a PHP fan. Starting from bundles, getting yourself around powerful console commands, injecting services, lazy loading concept, listeners, doctrine, twig, all to me is a fascinating and life changing concepts, bits and pieces. There are many more to be learned inside Symfony 2. I will see you in another post very soon ๐Ÿ™‚

Cheers!

Share

2 thoughts on “Five months with Symfony 2

Leave a Reply to sudhir k gupta Cancel reply

Your email address will not be published. Required fields are marked *