with your friend @weaverryan · > lead of the symfony documentation team > writer for...
TRANSCRIPT
![Page 1: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/1.jpg)
with your friend @weaverryan
![Page 2: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/2.jpg)
> Lead of the Symfony documentation team
> Writer for KnpUniversity.com
> Symfony fanboy/evangelist
> Husband of the much more talented @leannapelham
knpuniversity.com twitter.com/weaverryan
It’s-a me, Ryan!
> Father to my more handsome son, Beckett
![Page 3: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/3.jpg)
You have… a
superpower!
@weaverryan
![Page 4: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/4.jpg)
You know Drupal!
@weaverryan
![Page 5: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/5.jpg)
@weaverryan
> Object-Oriented Principles
> Namespaces
> Routes & Controllers*
> Service Container*
> Events & Event Listeners*
> Drupal Console*
Drupal 8 leverages:
* come from Symfony components
![Page 6: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/6.jpg)
Symfony
@weaverryan
![Page 7: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/7.jpg)
a collection of small PHP libraries
(the components)
@weaverryan
Symfony is…
![Page 8: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/8.jpg)
@weaverryan
glue that makes these components work together
The Symfony Framework is…
![Page 9: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/9.jpg)
@weaverryan
glue that makes these components work together
Drupal is…
???
![Page 10: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/10.jpg)
Drupal=
Route & Controller System
Container
+
full of many services (objects) that do EVERYTHING & give all CMS features
@weaverryan
![Page 11: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/11.jpg)
Symfony=
Route & Controller System
Container
+
full of almost zero services
@weaverryan
![Page 12: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/12.jpg)
Imagine Drupal… where you uninstalled every single module
(including core)
@weaverryan
That’s Symfony
![Page 13: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/13.jpg)
@weaverryan
… but you can install all the features you need.
Symfony is lean & mean…
![Page 14: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/14.jpg)
Let’s code!
@weaverryan
Follow the code at: http://bit.ly/dcon18-symfony
![Page 15: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/15.jpg)
composer create-project symfony/skeleton dcon18
![Page 16: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/16.jpg)
![Page 17: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/17.jpg)
![Page 18: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/18.jpg)
@weaverryan
![Page 19: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/19.jpg)
Hello Symfony Flex!
![Page 20: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/20.jpg)
@weaverryan
15 files
No Database
![Page 21: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/21.jpg)
@weaverryan
Let’s start the built-in PHP web server
![Page 22: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/22.jpg)
@weaverryan
http://localhost:8000/
![Page 23: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/23.jpg)
Create an API Endpoint
@weaverryan
![Page 24: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/24.jpg)
@weaverryan
Step 1: Controller(i.e. function that builds the page)
<?php// src/Controller/SongController.php namespace App\Controller;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; class SongController extends AbstractController{ public function apiWriteSong() { return $this->json([ 'I rode my truck, through some mud', ]); }}
![Page 25: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/25.jpg)
@weaverryan
# config/routes.yamlsong_api_write_song: path: /api/songs controller: App\Controller\SongController::apiWriteSong
Step 2: Route(i.e. URL that points to the controller)
![Page 26: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/26.jpg)
@weaverryan
* YES! No need to rebuild any cache!
@weaverryan
![Page 27: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/27.jpg)
@weaverryan
Your project is small
- service container
- routing system
- < 50 services
![Page 28: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/28.jpg)
Your project is small
> no templating
> no database/ORM
> no logging
> no koopa troopas
![Page 29: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/29.jpg)
Need something? Install it!
Drupal modules = Symfony bundles
@weaverryan
![Page 30: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/30.jpg)
Install annotations support
@weaverryan
![Page 31: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/31.jpg)
composer require annotations
![Page 32: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/32.jpg)
An alias (see symfony.sh)
![Page 33: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/33.jpg)
@weaverryan@weaverryan
![Page 34: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/34.jpg)
Recipes
![Page 35: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/35.jpg)
@weaverryan
Step 1 (of 1):Controller & Route
<?php // src/Controller/SongController.php// ...class SongController extends AbstractController{ /** * @Route("/api/songs") */ public function apiWriteSong() { return $this->json([ 'I rode my truck, through some mud', ]); }}
Hey! Annotations! Like Drupal Plugins!
![Page 36: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/36.jpg)
Let’s render a
template!
(Twig)
@weaverryan
![Page 37: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/37.jpg)
composer require twig
![Page 38: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/38.jpg)
![Page 39: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/39.jpg)
@weaverryan
# config/packages/twig.yamltwig: paths: ['%kernel.project_dir%/templates']
Automated configurationTwig
templates/ directory created automatically
![Page 40: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/40.jpg)
Create a new HTML page// src/Controller/SongController.php// ... /** * @Route("/another-song") */public function writeAnotherSong(){ $song = 'Back-road, boot-scooting, honkey-tonkin CMS'; return $this->render('song/anotherSong.html.twig', [ 'song' => $song, ]);}
{# templates/song/anotherSong.html.twig #}{% extends 'base.html.twig' %} {% block body %} <h1>{{ song }}</h1>{% endblock %}
![Page 41: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/41.jpg)
@weaverryan@weaverryan
![Page 42: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/42.jpg)
@weaverryan
Drupal Console?
Symfony has bin/console
![Page 43: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/43.jpg)
php bin/console debug:twig
![Page 44: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/44.jpg)
php bin/console debug:router
![Page 45: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/45.jpg)
Better debugging
tools!
(e.g. devel for Symfony)
@weaverryan
![Page 46: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/46.jpg)
composer require debug
![Page 47: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/47.jpg)
![Page 48: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/48.jpg)
@weaverryan@weaverryan
![Page 49: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/49.jpg)
@weaverryan@weaverryan
![Page 50: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/50.jpg)
More bundles
means more services
(e.g. the “logger” service)
@weaverryan
![Page 51: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/51.jpg)
public function writeAnotherSong() { $logger = \Drupal::getContainer()->get('logger'); $logger->debug($song); // ... }
Fetching Services in Drupal
… or you can / should use dependency injection and update a services YML file
( the cheating way)
![Page 52: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/52.jpg)
Fetching Services in Symfony
use Psr\Log\LoggerInterface; // ...
public function writeAnotherSong(LoggerInterface $logger) { $logger->debug($song); // ...}
Just ask for the service you need
![Page 53: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/53.jpg)
php bin/console debug:autowiring
![Page 54: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/54.jpg)
Organizing Code
// src/Service/SongGenerator.phpnamespace App\Service;class SongGenerator{ public function generateSong($noun) { $title = '...'; // magic song generator return $title; }}
![Page 55: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/55.jpg)
Organizing Code
// src/Controller/SongController.phpuse App\Service\SongGenerator; // ... /** * @Route("/api/songs") */public function apiWriteSong(SongGenerator $songGenerator) { return $this->json([ $songGenerator->generateSong('truck'), ]);}
![Page 56: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/56.jpg)
Let’s add a Database!
(doctrine)
@weaverryan
![Page 57: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/57.jpg)
composer require doctrine
![Page 58: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/58.jpg)
![Page 59: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/59.jpg)
![Page 60: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/60.jpg)
# .env###> doctrine/doctrine-bundle ### # Configure other settings in config/packages/doctrine.yamlDATABASE_URL=mysql://root:[email protected]:3306/dcon2018_symfony ###< doctrine/doctrine-bundle ###
.env ≈ settings.php
php bin/console doctrine:database:create
(creates a db… but it’s empty for now)
![Page 61: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/61.jpg)
composer require maker
php bin/console list make
![Page 62: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/62.jpg)
@weaverryan
Doctrine *also* has “entities”
one Entity class = one DB table
![Page 63: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/63.jpg)
php bin/console make:entity
![Page 64: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/64.jpg)
php bin/console make:entity
![Page 65: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/65.jpg)
// src/Entity/CountrySong.phpnamespace App\Entity;use Doctrine\ORM\Mapping as ORM; class CountrySong{ /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=255) */ private $title; // ... getTitle(), setTitle(), etc methods}
![Page 66: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/66.jpg)
php bin/console make:migration
// src/Migrations/Version20180409012347.phpclass Version20180409012347 extends AbstractMigration{ public function up(Schema $schema) { $this->addSql('CREATE TABLE country_song (id INT AUTO_INCREMENT NOT NULL, title VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); } public function down(Schema $schema) { // ... holds the opposite } }
![Page 67: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/67.jpg)
php bin/console doctrine:migrations:migrate
![Page 68: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/68.jpg)
Let’s create an API endpoint to save new
country songs
@weaverryan
![Page 69: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/69.jpg)
// src/Controller/SongController.php
use Doctrine\ORM\EntityManagerInterface;
/** * @Route("/api/songs", methods="POST") */public function apiWriteSong(SongGenerator $generator, EntityManagerInterface $em) { $song = new CountrySong(); $song->setTitle($generator->generateSong('truck')); $em->persist($song); $em->flush(); return $this->json([ 'title' => $song->getTitle(), 'id' => $song->getId(), ]);}
![Page 70: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/70.jpg)
Hmm… creating the JSON was too much work
@weaverryan
![Page 71: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/71.jpg)
public function apiWriteSong(SongGenerator $gen, EntityManagerInterface $em) { $song = new CountrySong(); $song->setTitle($gen->generateSong('truck')); $em->persist($song); $em->flush(); return $this->json($song);}
does that work? …. noop
![Page 72: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/72.jpg)
composer require serializerpublic function apiWriteSong(SongGenerator $gen, EntityManagerInterface $em) { $song = new CountrySong(); $song->setTitle($gen->generateSong('truck')); $em->persist($song); $em->flush(); return $this->json($song);}
![Page 73: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/73.jpg)
GET /api/songs/{id}
// src/Controller/SongController.php /** * @Route("/api/songs/{id}", methods="GET") */public function apiGetSong(CountrySong $song) { return $this->json($song);}
![Page 74: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/74.jpg)
Let’s generate a
CRUD
@weaverryan
![Page 75: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/75.jpg)
php bin/console make:crud
![Page 76: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/76.jpg)
php bin/console make:crud
![Page 77: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/77.jpg)
@weaverryan@weaverryan
![Page 78: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/78.jpg)
Security
@weaverryan
![Page 79: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/79.jpg)
composer require security-checker
![Page 80: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/80.jpg)
bin/console security:check
Flex will also give you a warning if you try to install a package with a known security vulnerability
![Page 81: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/81.jpg)
@weaverryan@weaverryan
![Page 82: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/82.jpg)
Bonus: API Platform
@weaverryan
![Page 83: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/83.jpg)
// src/Entity/CountrySong.php// .../** * @ApiResource() * @ORM\Entity() */class CountrySong{ // ..}
composer require api
![Page 84: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/84.jpg)
@weaverryan@weaverryan
![Page 85: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/85.jpg)
![Page 86: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/86.jpg)
![Page 87: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/87.jpg)
![Page 88: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/88.jpg)
http://localhost:8000/country_songs.json
![Page 89: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/89.jpg)
Bonus: Admin
Generator
@weaverryan
![Page 90: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/90.jpg)
composer require admin
# config/packages/easy_admin.yamleasy_admin: entities: # List the classes you want to manage - App\Entity\CountrySong
![Page 91: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/91.jpg)
@weaverryan@weaverryan
http://localhost:8000/admin
![Page 92: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/92.jpg)
Bonus: Webpack Encore
@weaverryan
![Page 93: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/93.jpg)
Drupal & Symfony
great, awkward, friends
@weaverryan
![Page 94: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/94.jpg)
Drupal SymfonyRouting &
Controllers
Container
modules bundles
Console Tool bin/console
OOP, namespaces, Composer, etc
✅
✅ (many services)
✅ (few services)
Plugins
Drupal Console
✅
✅ ✅
![Page 95: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/95.jpg)
Symfony Starts Tiny
> twig
> doctrine
> api
> logging
> cache
> debug
> … more at symfony.sh
… grows with you…
![Page 96: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/96.jpg)
Have a project that doesn’t need a CMS?
![Page 97: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/97.jpg)
Try Symfony!
(it’ll make you even better at Drupal anyways)
github.com/weaverryan/drupalcon18-symfony-for-drupalers
![Page 98: with your friend @weaverryan · > Lead of the Symfony documentation team > Writer for KnpUniversity.com > Symfony fanboy/evangelist > Husband of the much more talented @leannapelham](https://reader035.vdocuments.us/reader035/viewer/2022071019/5fd37b0599f9a172ca3c6d3a/html5/thumbnails/98.jpg)
Ryan Weaver @weaverryan
Free Symfony Video Tutorial: https://knpuniversity.com/tracks/symfony
THANK YOU DRUPALCON!