Symfony: installed your first bundle

Here you will learn how to installed bundles

what is bundle in symfony?
bundle is like a plugin, which provide service, and remember: service == tools

so there’s lot buddle to use, mostly you could found in this github page

so which bundle you should install and in what circumstance?
Honestly I do not very clair ideal either, what you should do is go to the link and read the document

and try it!!

Step 1 install one bundle

I found the basic usage bundle called: Monolog – Logging for PHP

here is github link

Go to the document page
And go to your terminal and type :

$ composer require logger

once installed you should be see the changed in your composer.json file :

"symfony/monolog-bundle": "^3.2",

Step 2 check the autowiring

go back to terminal

./bin/console debug:autowiring

then you should be able see you had add alias to monolog.logger

great, basic we had installed successful

Step 3 Injection class to test

go to your src/Controller/ArticleController.php

tried in function toggleArticleStar to inject LoggerInterface, give the varialbel called $logger

public function toggleArticleStar($slug, LoggerInterface $logger)

then return the message:so show the loggerInterface

$logger->notice('so show the loggerInterface');

go to your endPoint star part and click, then go to this file:


So yes!!! you you see the log is right here

This is just one of example bundle usage, and my first too, I hope you guys could get the point from this chapter and me too, way long to learn