Skip to main content
Submitted by admin on 18 March 2022

Symfony

Symfony is an open-source MVC based PHP framework for both web and console projects.

M:  All the Database operation takes place in the Model.

V:  All the User Interface  takes place in the View.

C:  All the business logic takes place in the Controller.

Symfony is sponsored by SensioLabs. It was developed by Fabien Potencier in 2005

Symfony is majorly a set of reusable PHP components and bundles. Their independent component is not strict with Symfony framework  and  can be used in any PHP project.

Installing Symfony Framework

Symfony can be install in two ways.

  1. Using Composer
  2. Using Symfony CLI

Using Composer

Composer is used for download/Install Symfony Components.

Step1: composer create-project symfony/skeleton my-project
Step2: cd my-project/
Step3: composer require webapp
Step4: php -S 127.0.0.1:8000 -t public
Step5: Open your browser and navigate to https://127.0.0.1:8000 or http://localhost:8000/. If everything is working, you'll see a welcome page.

Using Symfony CLI

Symfony CLI is a developer tool to help you build, run, and manage only your Symfony applications directly from your terminal.

install using Symfony CLI is recommended . Symfony CLI creates a binary called symfony that provides all the tools you need to develop and run your Symfony application locally.

cd my-project/
symfony server:start

Symfony_traditional

Run Your Symfony Applications

Open your console terminal, move into your new project directory and start the local web server as follows:

run_symfony

Open your browser and navigate to https://127.0.0.1:8000 or http://localhost:8000/. If everything is working, you'll see a welcome page

we

You can run Symfony applications with any web server (Apache, nginx, the internal PHP web server, etc.). However, Symfony provides its own web server to make you more productive while developing your applications.

Lets Understand term components and bundles

Components are collection of classes providing a single core functionality. For example, Cache component provides cache functionality, which can be added to any application.

Symfony components are being used by a lot of open source projects that include Composer, Drupal, and phpBB.

Kernel component is the heart of the system. Kernel is basically the ‘main class’ that manages the environment and has the responsibility of handling a http request.

HttpKernel is the core component of the Symfony web framework.

A Symfony bundle is a collection of files and folders organized in a specific structure. The bundles are modeled in such a way that it can be reused in multiple applications. The main application itself is packaged as a bundle and it is generally called AppBundle

 Bundles In Symfony versions prior to 4.0, it was recommended to organize your own application code using bundles. This is no longer recommended and bundles should only be used to share code and features between multiple applications.

Path where Bundles must be enabled    [Root directory]/config/bundles.php file:

 

Feature

  • The core features of Symfony framework are implemented with bundles (FrameworkBundle, SecurityBundle, DebugBundle, etc.) They are also used to add new features in your application via third-party bundles.

Start Coding!