sajad torkamani

Make sure you install the Symfony CLI first.

Create project

symfony new my_project_directory --version="<latest-version" --webapp

Create database:

php bin/console doctrine:database:create

Create example page

src/Controller/HomeController.php:

<?php

namespace App\Controller;

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

class HomeController extends AbstractController
{
    #[Route('/')]
    public function index(): Response
    {
        return $this->render('home/index.html.twig');
    }
}

templates/home/index.html.twig:

{% extends 'base.html.twig' %}

{% block body %}
    <h1>Hello world</h1>
{% endblock %}

Start server

symfony server:start

Go to http://localhost:8000 to view your homepage.

Sources

Tagged: Symfony

Leave a comment

Your email address will not be published. Required fields are marked *