Post

Symfony – Organisation d’un projet Symfony

Symfony – Organisation d’un projet Symfony

Cours 40 — Organisation d’un projet Symfony

Introduction

Symfony impose une organisation claire des fichiers et des dossiers.

Cette structure facilite la maintenance et la compréhension du projet.


Dossier principal

1
mon_projet/

Contient l’ensemble de l’application.


Dossier src

1
src/

Contient le code PHP de l’application.


Contrôleurs

1
src/Controller/

Exemple :

1
2
PatientController.php
SejourController.php

Entités

1
src/Entity/

Exemple :

1
2
3
Patient.php
Sejour.php
User.php

Repositories

1
src/Repository/

Exemple :

1
PatientRepository.php

Formulaires

1
src/Form/

Exemple :

1
PatientFormType.php

Services

1
src/Service/

Exemple :

1
CalculAgeService.php

Templates Twig

1
templates/

Exemple :

1
2
templates/patient/
templates/sejour/

Fichiers publics

1
public/

Contient :

1
2
3
4
images
css
javascript
index.php

Configuration

1
config/

Contient :

1
2
3
services.yaml
routes.yaml
packages/

Migrations

1
migrations/

Contient les fichiers de migration Doctrine.


Comprendre le projet

1
2
3
4
5
6
7
8
9
Route
↓
Contrôleur
↓
Entity
↓
Repository
↓
Twig

Schéma simplifié

1
2
3
4
5
6
7
8
9
10
11
12
src/
├── Controller
├── Entity
├── Repository
├── Form
└── Service

templates/

config/

public/

Conclusion

Symfony organise automatiquement les fichiers selon leur rôle.

Dossiers à retenir :

1
2
3
4
5
6
7
8
Controller
Entity
Repository
Form
Service
templates
config
public
This post is licensed under CC BY 4.0 by the author.