composer symfony code example

Example 1: symfony install website skeleton

# run this if you are building a traditional web application
 composer create-project symfony/website-skeleton my_project_name

Example 2: symfony demo with composer

$ composer create-project symfony/symfony-demo my_project

Example 3: symfony

<?php
// src/Controller/LuckyController.php
namespace App\Controller;

use Symfony\Component\HttpFoundation\Response;

class LuckyController
{
    public function number(): Response
    {
        $number = random_int(0, 100);

        return new Response(
            '<html><body>Lucky number: '.$number.'</body></html>'
        );
    }
}

Example 4: symfony new project

# use the most recent LTS version
$ symfony new my_project_name --version=lts

# use the 'next' Symfony version to be released (still in development)
$ symfony new my_project_name --version=next

# you can also select an exact specific Symfony version
$ symfony new my_project_name --version=4.4

# The --full option installs all the packages that you usually need to build web applications.

Tags:

Misc Example