symfony2 Getting started with symfony2

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Remarks

This section provides an overview of what Symfony2 is and why a developer might want to use it.

It should also mention any large subjects within Symfony2 and link out to the related topics. Since the Documentation for Symfony2 is new, you may need to create initial versions of those related topics.

Versions

The latest stable version during the time of writing is Symfony 3.1 which will be maintained until end of July 2017.

Symfony has Long Term Support versions which are maintained for a total of 4 years (3 years for bug fixes, 1 additional year for security bug fixes)

A Standard Minor Version is maintained for an eight month period for bug fixes, and for a fourteen month period for security issue fixes.

Long Term Support versions:

Symfony 2.3 - May 2016 end of support for bug fixes
              May 2017 end of support for security fixes(end of life)

Symfony 2.7 - May 2018 end of support for bug fixes
              May 2019 end of support for security fixes(end of life)

Symfony 2.8 - November 2018 end of support for bug fixes
              November 2019 end of support for security fixes(end of life)

Starting from 3.X version, minor versions will be limited to 5 and the last minor version will be LTS.

Syfmony has dual maintenance mode, releasing minor versions ever six months once in May and once in November. Major version are released every two years, meaning there will be one year time period to move form the previous major version to the latest one, giving user a choice between the latest features of standard version or an LTS version that is supported for bug fixes.

Symfony maintains strict backward compatibility, anything that breaks BC is done in the next major version. A feature implementation that is an improvement but breaks BC is kept alongside the old implementation which will be deprecated

Read more about versions and development process in detail from the official documentation [here][1]

[1]: http://symfony.com/doc/current/contributing/community/releases.html| Version | Release Date | | ------- | ------------ | | 2.3.0 | 2013-06-03 | | 2.7.0 | 2015-05-30 | | 2.8.0 | 2015-11-30 |

Installation or Setup

Symfony Framework - built with symfony components, is one of the leading PHP framework used to create robust websites and web applications.

Symfony can be installed quickly through two recommended ways.

  1. The official documentaion recommends to install the framework through the Symfony Installer which is a tiny php application that is installed once on the local system that helps in downloading the framework and setting up the configuration of the framework. Symfony Installer requires PHP 5.4 or higher. To install on legacy php version use Composer.
  2. Through the PHP dependency manager Composer

Installing through Symfony Installer

On Linux/Mac OS X run the following commands:

$ sudo curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony
$ sudo chmod a+x /usr/local/bin/symfony
 

On Windows move to the project directory and run the following command:

php -r "file_put_contents('symfony', file_get_contents('https://symfony.com/installer'));"
 

symfony project can be created by running symfony new my_project [2.8] on Linux/Mac OS X

On Windows php symfony new my_project [2.8]

or alternatively symfony new my_project lts will use the latest long-term support version of Symfony.

Installation through Composer

  • Download Composer

  • Use Composer's create-project command to download Symfony

    composer create-project symfony/framework-standard-edition my_project_name ["2.8.*"]
     

Excellent detailed official documentation here

Running the Symfony application

For starting symfony internal web server (available since PHP 5.4), go to the project directory and execute this command:

for symfony<=2.8

php app/console server:start
 

and for symfony >=3.0

php bin/console server:start
 

This starts the web server at localhost:8000 in the background that serves your Symfony application. Then, open your browser and access the http://localhost:8000/ URL to see the Symfony welcome page:

enter image description here

Installing and Configuring Symfony

Checking Requirements

Run bin/symfony_requirements for checking symfony requirements and php cli setting. Install all packages that needed to run a symfony project. Setting your php.ini for example setting timezone and short_open_tag. Setting both php.ini for your php webserver (eg: /etc/php/apache2/php.ini) and php cli (eg: /etc/php/cli/php.ini). Open http://localhost/config.php for checking php webserver setting. If everything has passed, you are ready to run your symfony project.

Running Project

Run composer install to install all depedencies. Then setting up permission for var/cache , var/logs and var/sessions .

Detailed official documentation here

Simplest example in Symfony

  1. Install symfony correctly as guided above.
  2. Start symfony server if you are not installed in www directory.
  3. Ensure http://localhost:8000 is working if symfony server is used.
  4. Now it is ready to play with simplest example.
  5. Add following code in a new file /src/AppBundle/Controller/MyController.php in symfony installation dir.
  6. Test the example by visiting http://localhost:8000/hello
    (If you are not using Symfony's built-in http server, visit http://localhost/(symfony-dir)/web/app_dev.php/hello)
  7. That's all. Next: use twig to render the response.
<?php
// src/AppBundle/Controller/MyController.php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;

class MyController
{
    /**
     * @Route("/hello")
     */
    public function myHelloAction()
    {
        return new Response(
            '<html><body>
                   I\'m the response for request <b>/hello</b>
             </body></html>'
        );
    }
}
 

NOTE: All controller classes should have ends with word 'Controller' and methods related to routs should ends with word 'Action'. Further, In which controller your Actions are placed is not relevant until you define a rout prefix for the controller.



Got any symfony2 Question?