Create new Symfony project
26 May 2022 (Updated 20 August 2023)
On this page
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
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment