Create your first bundle | Symfony 2 | Beginners Guide

Hi All,

Welcome back. Today I am going to focus your attention on bundles. Well, the bundle is the most famous term you will frequently hear, during your adventure in Symfony 2. Actually, the bundle is a really handy feature which has been introduced by any PHP framework (not quite sure about rest of the frameworks) so far. Well, a Bundle is a package, collection of views, entities, controllers and so on. You can organize your code around bundles in a very smart way. And if you use bundles smartly, you can develop a system with highly independent features. Why not we discuss some examples before creating bundles,

  • Example 1 : Assume you are creating a basic employee management system. The basic features in a employee management system are employee registration, employee profile, employee payroll, employee attendance and so on. For employee registration, we have a separate UI with relevant registration form fields, we have separate functions (let’s call them controllers), such as checking existence of the employee, validity of the user input values, validity of employee national insurance number (in UK), and so on. And also, we got separate tables to insert values once the user submitted his/her employee registration form. Likewise we can group things (mainly model, view and controllers) in a functional way (but, it’s totally up to you). We call  these grouped things as ‘bundles‘ in Symfony 2.
  • Example 2: Let’s say you are creating a shopping cart system. In a shopping cart system, we know there are products, categories, sub categories, payment methods and so on. In here, we can have a separate bundles for products, categories and so on. For an example, inside categories bundle, we can nicely arrange things which are mostly relevant to managing categories. These things can be views (html and associated js, css files and so on), models (tables, schema and so on) and controllers (functions such as adding a category, deleting category and so on). So, in here, we are arranging bundles in a logical way. Likewise, you can organize your bundles for products, sub categories and so on. Continue reading