WEBVTT

NOTE Created by CaptionSync from Automatic Sync Technologies www.automaticsync.com

00:00:01.056 --> 00:00:04.996 align:middle
Rendering a template is pretty common, so
there's a shortcut when you're in a controller.

00:00:05.966 --> 00:00:09.976 align:middle
Replace all of this code with
a simple return $this-&gt;render:

00:00:12.906 --> 00:00:13.506 align:middle
That's it.

00:00:13.936 --> 00:00:15.296 align:middle
Make sure this works by refreshing.

00:00:16.736 --> 00:00:20.276 align:middle
So what does this magic-looking
render() function actually do?

00:00:20.796 --> 00:00:21.466 align:middle
Let's find out!

00:00:22.806 --> 00:00:28.086 align:middle
Hold command or control (depending on your
OS) and click render() to be taken straight

00:00:28.086 --> 00:00:30.666 align:middle
into the base Controller class
where this function lives:

00:00:31.106 --> 00:00:34.206 align:middle
deep in the heart of Symfony: Ah, hah!

00:00:34.786 --> 00:00:40.026 align:middle
In reality, this function simply goes out to
the templating service - just like we did -

00:00:40.196 --> 00:00:42.546 align:middle
and calls a method named renderResponse().

00:00:42.546 --> 00:00:48.006 align:middle
This method is like the render() function
we called, except that it wraps the HTML

00:00:48.006 --> 00:00:50.566 align:middle
in a Response object for convenience.

00:00:50.566 --> 00:00:55.106 align:middle
Here's the point: the base Controller class
has a lot of shortcut methods that you'll use.

00:00:55.666 --> 00:01:00.396 align:middle
But behind the scenes, these don't activate
some weird, core functionality in Symfony.

00:01:01.096 --> 00:01:06.216 align:middle
Instead, everything is done by one
of the services in the container.

00:01:06.536 --> 00:01:10.976 align:middle
Symfony doesn't really do anything: all
the work is done by different services.

00:01:17.046 --> 00:01:20.046 align:middle
Oh, you want to know what other
services are hiding in the container?

00:01:20.386 --> 00:01:25.106 align:middle
Me too! To find that out, head back to
the terminal and use the handy console:

00:01:28.336 --> 00:01:33.916 align:middle
Check out that debug:container
command - run that!

00:01:33.916 --> 00:01:36.656 align:middle
You should see a short list of service.

00:01:36.996 --> 00:01:42.186 align:middle
Ah, I mean, you should see over
200 useful objects in Symfony

00:01:42.226 --> 00:01:44.336 align:middle
that you get access to out of the box.

00:01:44.336 --> 00:01:47.946 align:middle
But don't worry about memorizing
these: as you use Symfony,

00:01:48.056 --> 00:01:51.556 align:middle
you'll find out which ones are important
to you and your project by reading the docs

00:01:51.556 --> 00:01:53.146 align:middle
on how to accomplish different things.

00:01:53.846 --> 00:01:56.076 align:middle
But sometimes, you can just guess!

00:01:56.586 --> 00:01:59.136 align:middle
For example, does Symfony
have a service for logging?

00:01:59.686 --> 00:02:00.716 align:middle
Um, maybe?!

00:02:01.556 --> 00:02:05.446 align:middle
We could Google that, or we could pass
an argument to this command to search

00:02:05.526 --> 00:02:10.646 align:middle
for services matching "log": Wow, there are 18!

00:02:11.496 --> 00:02:15.786 align:middle
Here's a secret: the service you usually
want is the one with the shortest name.

00:02:16.176 --> 00:02:17.616 align:middle
In this case: logger.

00:02:17.716 --> 00:02:21.946 align:middle
So if you wanted to log something, just
grab this out of the container and use it.

00:02:21.946 --> 00:02:25.326 align:middle
This command also shows you
what class you'll get back,

00:02:25.726 --> 00:02:28.976 align:middle
which you can use to find the methods on it.

00:02:29.046 --> 00:02:32.786 align:middle
We just figured this out
without any documentation.

00:02:33.716 --> 00:02:36.716 align:middle
There's a lot more to say later
about services and the container.

00:02:36.716 --> 00:02:40.726 align:middle
In fact, it's one of the most
fundamentally important things

00:02:40.726 --> 00:02:42.346 align:middle
that makes Symfony so special...

00:02:42.606 --> 00:02:43.816 align:middle
and so fast.

