LogoLogo
Docs officielsTutos officiels
Symfony-6-LP
Symfony-6-LP
  • Présentation
  • LP
    • Planning
    • Travail à rendre
    • Séance 1 : Introduction
    • Séance 1 : Eco-Système de Symfony
    • Séance 1 : installation
    • Séance 1 : Architecture de Symfony
    • Séance 1 : Première page avec Symfony
    • Séance 2 : Controller et Routes
    • Séance 2 : Vues - TWIG
    • Séance 4 : Exercices
    • Séance 5 : Modèles - Entités - ORM
    • Séance 6 : Relations entre entités
    • Séance 7 : Formulaires
    • Séance 8 : Sécurité
  • Semestre 4
    • Formulaires
    • Webpack
    • Repository
    • Personnaliser TWIG
    • Services
    • Services et Injection de dépendances
    • Les Bundles
  • FAQ
  • Mise en production
  • Créer un environnement Symfony collaboratif
Propulsé par GitBook
Sur cette page

Cet article vous a-t-il été utile ?

Exporter en PDF
  1. Semestre 4

Services et Injection de dépendances

Fetching Services

Symfony comes packed with a lot of useful objects, called services. These are used for rendering templates, sending emails, querying the database and any other "work" you can think of.

If you need a service in a controller, type-hint an argument with its class (or interface) name. Symfony will automatically pass you the service you need:

1 2 3 4 5 6 7 8 9 10 11

use Psr\Log\LoggerInterface 

//...

/**
* @Route("/lucky/number/{max}")
*/
public function number($max, LoggerInterface $logger)
{
 $logger->info('We are logging!');
 // ...
}
  • Awesome!

PrécédentServicesSuivantLes Bundles

Dernière mise à jour il y a 2 ans

Cet article vous a-t-il été utile ?