PHP

  minte9
REMEMBERS




Last update:   12-02-2022

Flex

Symfony Flex is a Composer plugin already installed with Symfony.
 
# Project

composer create-project symfony/skeleton flex
cd flex/


## Recipe

# Twig is not the name of a Composer package (it is a Flex alias).  
# Flex resolves that alias for Composer.  

# Flex installs a recipe for symfony/twig-bundle.  
# A recipe is a way for a library to automatically configure itself.  

composer require twig
composer require profiler
composer require api

composer remove api
composer remove vendor/package

symfony server:start
http://localhost:8000   # Welcome to Symfony

Twig

Twig is a fast and secure template engine for PHP.
 
/**
 * DefaultController
 * 
 * src/Controller/DefaultController
 * 
 * Starting from Symfony 5.0 support for PHP templates was removed.
 * Only Twig templates can be used.
 * 
 * http://localhost:8000/hello              # Hello WORLD
 * http://localhost:8000/hello/Symfony      # Hello SYMFONY
 * 
 */

namespace App\Controller;

use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class DefaultController extends AbstractController 
{
    /**
     * @Route("/hello/{name}")
     */
    public function hello($name='World')
    {
        return $this->render('default/index.html.twig', [
            'name' => $name,
        ]);
    }
}

Templates

Twig compiles templates down to plain optimized PHP code.
 
{% include 'header.html.twig' %}

<b>Hello {{name|upper}}</b>

Questions     github Symfony
Controllers
        A B C D E F
🔔
1/2