\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{AGD (agarciadutaitre)} \pdfinfo{ /Title (les-commandes-symfony.pdf) /Creator (Cheatography) /Author (AGD (agarciadutaitre)) /Subject (Les commandes Symfony Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A31774} \definecolor{LightBackground}{HTML}{F9F0F6} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Les commandes Symfony Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{AGD (agarciadutaitre)} via \textcolor{DarkBackground}{\uline{cheatography.com/174798/cs/36722/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}AGD (agarciadutaitre) \\ \uline{cheatography.com/agarciadutaitre} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 7th March, 2023.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{x{1.74195 cm} x{3.23505 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Création application : symfony new}} \tn % Row 0 \SetRowColor{LightBackground} LTS web & my\_project -{}-version=lts -{}-webapp \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Version 6.2 web & my\_project -{}-version="6.2.*" -{}-webapp \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} LTS & my\_project -{}-version=lts \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} La dernière version & my\_project \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} la demo & symfony new demo –demo \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{LTS signifie Long Time Support soit version supportée sur le long terme.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Création inscription et connexion}} \tn % Row 0 \SetRowColor{LightBackground} & symfony console \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} connexion (login) & make:auth \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} Inscription (register) & \seqsplit{make:registration-form} \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} & make:user \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Créer les formulaires pour l'inscription et la connexion des utilisateurs ainsi que le contrôleur user adapté} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Création d'une route par configuration}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Ajouter dans le fichier {\bf{config/routes.yaml}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{nom\_de\_la\_route:}}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~{\bf{path:}} /inscription ou / ou /machin/truc etc (url)} \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~{\bf{controller:}} App\textbackslash{}Controller\textbackslash{}nom\_du\_controleurController::nom\_de\_methode} \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Liste des routes du projet}} \tn % Row 0 \SetRowColor{LightBackground} liste toutes les routes & php bin/console debug:router \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} liste une route & php bin/console debug:router \textless{}nom de la route\textgreater{} \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} liste l'enchainement des fonctions utilisées & php bin/console router:match \textless{}nom de la route\textgreater{} \tn % Row Count 8 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.09034 cm} x{2.88666 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Symfony}} \tn % Row 0 \SetRowColor{LightBackground} server:start -{}-no-tls & lance le serveur en http \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{server:ca:install} & pour un serveur en https \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} server:start -d & en background \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} server:stop & stop le serveur (ctr c) \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} console about & information version du projet \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} \seqsplit{check:requirements} & valide l'environnement \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.33919 cm} x{2.63781 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{symfony console}} \tn % Row 0 \SetRowColor{LightBackground} list & donne la liste de toutes les commandes \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} liste make & donne la liste des commandes du maker \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} make:controller -{}-help & donne la liste des options de la commande \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{doctrine:database:create} & Crée la db déclarée dans .env \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} d:d:c & Crée la db déclarée dans .env \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} make:user & Crée la table user associée à l'authentification \tn % Row Count 13 (+ 3) % Row 6 \SetRowColor{LightBackground} make:entity & Crée une table \tn % Row Count 14 (+ 1) % Row 7 \SetRowColor{white} make:entity -{}-regenerate & Généré les méthodes getter et setter manquantes \tn % Row Count 17 (+ 3) % Row 8 \SetRowColor{LightBackground} make:entity -{}-overwrite & Regénére toutes les méthodes getter et setter \tn % Row Count 20 (+ 3) % Row 9 \SetRowColor{white} make:migration & Génère les fichiers de migration \tn % Row Count 22 (+ 2) % Row 10 \SetRowColor{LightBackground} \seqsplit{doctrine:migrations:migrate} & Exécute les fichiers de migration \tn % Row Count 24 (+ 2) % Row 11 \SetRowColor{white} m:mig & Génère les fichiers de migration \tn % Row Count 26 (+ 2) % Row 12 \SetRowColor{LightBackground} d:m:m & Exécute les fichiers de migration \tn % Row Count 28 (+ 2) % Row 13 \SetRowColor{white} \seqsplit{doctrine:migrations:diff} & Génère un fichier de migration en comparant le schéma interne et le schéma de la base \tn % Row Count 33 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.33919 cm} x{2.63781 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{symfony console (cont)}} \tn % Row 14 \SetRowColor{LightBackground} debug:autowiring & Liste les classes autochargeable \tn % Row Count 2 (+ 2) % Row 15 \SetRowColor{white} debug:container & Liste les services disponibles pour l'application \tn % Row Count 5 (+ 3) % Row 16 \SetRowColor{LightBackground} dbal:run-sql 'SELECT * FROM product' & interroge la base de données \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Les fichiers de migrations sont nommés migrations\textbackslash{}Versiondateheure.php et ils contiennent les ordres sql qui vont modifier la base} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.34379 cm} x{3.63321 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{php bin/console}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{server:dump} & ?? \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{server:log} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} list & liste les commandes de console \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} list make & liste les commandes du maker \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.69218 cm} x{3.28482 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Contrôleur}} \tn % Row 0 \SetRowColor{LightBackground} Créer un contrôleur & php bin/console make:controller nom\_du\_controleur \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} & symfony console make:controller nom\_du\_controleur \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.79172 cm} x{3.18528 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Les vues}} \tn % Row 0 \SetRowColor{LightBackground} Installation & composer require twig \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Les vues = Twig sous symfony} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Exemples de déclaration de route}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\#{[}Route('/api/posts/\{id\}', methods: {[}'GET', 'HEAD'{]}){]} \newline % Row Count 2 (+ 2) \#{[}Route( '/contact', name: 'contact', \newline % Row Count 3 (+ 1) condition: "context.getMethod() in {[}'GET', 'HEAD'{]} and \seqsplit{request.headers.get('User-Agent')} matches '/firefox/i'", \newline % Row Count 6 (+ 3) // expressions can also include config parameters: \newline % Row Count 8 (+ 2) // condition: \seqsplit{"request.headers.get('User-Agent')} matches \seqsplit{'\%app.allowed\_browsers\%'"} \newline % Row Count 10 (+ 2) ){]} \newline % Row Count 11 (+ 1) \#{[}Route( \newline % Row Count 12 (+ 1) '/posts/\{id\}', \newline % Row Count 13 (+ 1) name: 'post\_show', \newline % Row Count 14 (+ 1) // expressions can retrieve route parameter values using the "params" variable \newline % Row Count 16 (+ 2) condition: "params{[}'id'{]} \textless{} 1000" \newline % Row Count 17 (+ 1) ){]} \newline % Row Count 18 (+ 1) // Controller (using an alias): \newline % Row Count 19 (+ 1) \#{[}Route( '/posts/\{id\}', name: 'post\_show', \newline % Row Count 20 (+ 1) condition: \seqsplit{"service('route\_checker')}.check(request)"){]} \newline % Row Count 22 (+ 2) use Symfony\textbackslash{}Bundle\textbackslash{}FrameworkBundle\textbackslash{}Routing\textbackslash{}Attribute\textbackslash{}AsRoutingConditionService; \newline % Row Count 24 (+ 2) use Symfony\textbackslash{}Component\textbackslash{}HttpFoundation\textbackslash{}Request; \newline % Row Count 25 (+ 1) \#{[}AsRoutingConditionService(alias: 'route\_checker'){]} \newline % Row Count 27 (+ 2) class RouteChecker \newline % Row Count 28 (+ 1) \{ \newline % Row Count 29 (+ 1) ~~public function check(Request \$request): bool \newline % Row Count 31 (+ 2) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Exemples de déclaration de route (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~\{ \newline % Row Count 1 (+ 1) // ... \newline % Row Count 2 (+ 1) ~~\} \newline % Row Count 3 (+ 1) \}% Row Count 4 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} x{4.4793 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{php}} \tn % Row 0 \SetRowColor{LightBackground} -m & liste les modules php installés \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.43873 cm} x{2.53827 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Composer require}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{https://packagist.org/packages/symfony/} & Liste des packages dispo sur composer \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} symfony/orm-pack & Installe Doctrine \tn % Row Count 4 (+ 1) % Row 2 \SetRowColor{LightBackground} -{}-dev \seqsplit{symfony/maker-bundle} & Installe le Maker \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} symfony/validator & Les contraintes de validation pour Forms et DB \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} \seqsplit{symfony/http-foundation} & installe session \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} symfony/form & Installe les formulaires \tn % Row Count 13 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.58804 cm} x{2.38896 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Usage des annotations pour les routes}} \tn % Row 0 \SetRowColor{LightBackground} Utiliser le package annotation & composer require annotations \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Création route annotation}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textless{}?php \newline namespace App\textbackslash{}Controller; \newline \newline use Symfony\textbackslash{}Component\textbackslash{}HttpFoundation\textbackslash{}Response; \newline use Symfony\textbackslash{}Component\textbackslash{}Routing\textbackslash{}Annotation\textbackslash{}Route; \newline \newline class \seqsplit{NomDuControleurController} \{ \newline \newline /{\emph{* \newline }} @Route( \newline {\emph{ "/chemin\_de\_url/\{param1\}\}", \newline }} \seqsplit{name="nom\_de\_la\_route"}, \newline {\emph{ methods=\{"GET", "POST","HEAD","PUT",etc\}, \newline }} requirements=\{"param1":"regexpVoulue" \}, \newline {\emph{ defaults=\{"param1":"ValeurParDefaut"\} \newline }} host="my.host" \newline {\emph{ schemes=\{"http", "https"\} \newline }} priority=1 \newline {\emph{ ) \newline }}/ \newline public function nomTraitement(\$param1 ): Response \{ \newline // ... \newline \newline return \$this-\textgreater{}render('nom\_rep\_template/nom\_du\_template.html.twig', {[} \newline 'nomDuParametre' =\textgreater{} \$valeur\_du\_parametre, \newline 'param1' \$param1, \newline {]}); \newline \} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Option pour les routes}} \tn % Row 0 \SetRowColor{LightBackground} name="routeName" & Donner un nom à une Route \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} methods=\{"method1", "method2"\} & retreindre l'accès au requête HTTP de type \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} Type de requête HTTP & GET,POST,DEL,PUT,HEAD etc \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} host="nom ou IP du host" & retreindre l'accès à un host en particulier \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} requirements=\{"param1":"regexp1", "param2":"regexp2"\} & appliquer des règles aux paramètres \tn % Row Count 14 (+ 4) % Row 5 \SetRowColor{white} defaults=\{"param1":"default1", "param2":"default2"\} & Valeur par defaults des paramètres \tn % Row Count 17 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Création d'un contrôleur en lien avec la base}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{// \seqsplit{src/Controller/ProductController}.php \newline namespace App\textbackslash{}Controller; \newline \newline // ... \newline use App\textbackslash{}Entity\textbackslash{}Product; \newline use Doctrine\textbackslash{}Persistence\textbackslash{}ManagerRegistry; \newline use Symfony\textbackslash{}Component\textbackslash{}HttpFoundation\textbackslash{}Response; \newline use Symfony\textbackslash{}Component\textbackslash{}Routing\textbackslash{}Annotation\textbackslash{}Route; \newline \newline class ProductController extends AbstractController \newline \{ \newline \#{[}Route('/product', name: 'create\_product'){]} \newline public function \seqsplit{createProduct(ManagerRegistry} \$doctrine): Response \newline \{ \newline \$entityManager = \$doctrine-\textgreater{}getManager(); \newline \newline \$product = new Product(); \newline \$product-\textgreater{}setName('Keyboard'); \newline \$product-\textgreater{}setPrice(1999); \newline \$product-\textgreater{}setDescription('Ergonomic and stylish!'); \newline \newline // tell Doctrine you want to (eventually) save the Product (no queries yet) \newline \$entityManager-\textgreater{}persist(\$product); \newline \newline // actually executes the queries (i.e. the INSERT query) \newline \$entityManager-\textgreater{}flush(); \newline \newline return new Response('Saved new product with id '.\$product-\textgreater{}getId()); \newline \} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Tester le contrôleur avec : \seqsplit{http://localhost:8000/product} \newline Vérifier la base de donnée : php bin/console dbal:run-sql 'SELECT * FROM product' \newline https://symfony.com/doc/current/doctrine.html\#migrations-creating-the-database-tables-schema} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}