WEBVTT

NOTE Created by CaptionSync from Automatic Sync Technologies www.automaticsync.com

00:00:01.016 --> 00:00:04.606 align:middle
This page has a boring, hardcoded URL.

00:00:05.636 --> 00:00:10.606 align:middle
What our aquanauts deserve is a dynamic
route that can handle the URL for any genus -

00:00:10.956 --> 00:00:19.456 align:middle
like /genus/octopus or /genus/hippocampus
which is the genus that sea horses belong to.

00:00:20.016 --> 00:00:21.866 align:middle
Oh man, sea horses are cute.

00:00:22.736 --> 00:00:32.696 align:middle
How? Change the URL to /genus/{genusName}:
This genusName part could be named anything:

00:00:33.066 --> 00:00:36.386 align:middle
the important part is that it
is surrounded by curly braces.

00:00:36.636 --> 00:00:42.386 align:middle
As soon as you do this, you are allowed to
have a $genusName argument to your controller.

00:00:42.986 --> 00:00:48.116 align:middle
When we go to /genus/octopus this
variable will be set to octopus.

00:00:48.236 --> 00:00:49.866 align:middle
That's pretty awesome.

00:00:50.446 --> 00:00:54.326 align:middle
The important thing is that the routing
wildcard matches the variable name.

00:00:54.326 --> 00:00:58.886 align:middle
To test this is, change the message
in the response to 'The genus: '.

00:00:59.246 --> 00:01:03.816 align:middle
$genusName: Head back to
the browser and refresh.

00:01:03.816 --> 00:01:07.076 align:middle
Ah! A 404 error.

00:01:07.076 --> 00:01:14.006 align:middle
That's because the URL is no longer
/genus, it's now /genus/something:

00:01:14.456 --> 00:01:17.146 align:middle
we have to have something on
the other side of the URL.

00:01:17.266 --> 00:01:21.246 align:middle
Throw octopus on the end
of that (/genus/octopus).

00:01:21.246 --> 00:01:22.376 align:middle
There's the new message.

00:01:22.716 --> 00:01:25.126 align:middle
And of course, we could change
this to whatever we want.

00:01:25.306 --> 00:01:29.646 align:middle
So what would happen if the wildcard
and the variable name didn't match?

00:01:30.046 --> 00:01:34.206 align:middle
Um I don't know: let's try it:
change the wildcard name and refresh!

00:01:36.846 --> 00:01:41.626 align:middle
OMG: that's a sweet error: The
Controller::showAction() requires

00:01:41.626 --> 00:01:44.146 align:middle
that you provide a value
for the $genusName argument.

00:01:44.836 --> 00:01:49.516 align:middle
What Symfony is trying to tell
you is: Hey fellow ocean explorer,

00:01:49.956 --> 00:01:55.196 align:middle
I'm trying to call your showAction(), but I
can't figure out what value to pass to genusName

00:01:55.476 --> 00:01:59.286 align:middle
because I don't see a {genusName}
wildcard in the route.

00:01:59.796 --> 00:02:01.036 align:middle
I'm shore you can help me.

00:02:02.026 --> 00:02:04.496 align:middle
As long as those always match, you'll be great.

00:02:05.726 --> 00:02:09.276 align:middle
When you load this page, Symfony loops
over all the routes in your system

00:02:09.276 --> 00:02:14.026 align:middle
and asks them one-by-one:
do you match /genus/octopus?

00:02:14.356 --> 00:02:17.916 align:middle
Do you match /genus/octopus?

00:02:17.916 --> 00:02:23.896 align:middle
As soon as it finds one route that matches
that URL, it stops and calls that controller.

00:02:24.036 --> 00:02:31.066 align:middle
So far, we only have one route, but eventually
we'll have a lot, organized across many files.

00:02:31.706 --> 00:02:35.876 align:middle
It would be swimming if we could
get a big list of every route.

00:02:36.546 --> 00:02:37.766 align:middle
Ha! We can!

00:02:37.836 --> 00:02:41.646 align:middle
Symfony comes with an awesome
debugging tool called the console.

00:02:42.176 --> 00:02:49.466 align:middle
To use it, go to the terminal and run This
returns a big list of commands that you can run.

00:02:49.996 --> 00:02:53.026 align:middle
Most of these help you with
debugging, some generate code

00:02:53.246 --> 00:02:55.216 align:middle
and others do things like clear caches.

00:02:56.166 --> 00:02:58.786 align:middle
We're interested in debug:router.

00:02:59.256 --> 00:03:03.346 align:middle
Let's run that: Nice!

00:03:03.736 --> 00:03:05.366 align:middle
This prints out every route.

00:03:05.766 --> 00:03:09.146 align:middle
You can see our route at the
bottom: /genus/{genusName}.

00:03:09.146 --> 00:03:14.066 align:middle
But there are other routes, I
wonder where those are coming from?

00:03:14.806 --> 00:03:16.756 align:middle
Those routes give you some debugging tools -

00:03:16.846 --> 00:03:19.206 align:middle
like the little web debug
toolbar we saw earlier.

00:03:19.536 --> 00:03:21.446 align:middle
I'll show you where these are coming from later.

00:03:22.136 --> 00:03:24.546 align:middle
When we add more routes later,
they'll show up here too.

00:03:25.336 --> 00:03:26.746 align:middle
Ok, fun fact!

00:03:27.266 --> 00:03:29.366 align:middle
A baby seahorse is called a "fry".

00:03:30.096 --> 00:03:31.856 align:middle
How about a relevant fun fact?

00:03:32.386 --> 00:03:34.726 align:middle
You now know 50% of Symfony.

00:03:34.916 --> 00:03:36.806 align:middle
Was that really hard?

00:03:37.066 --> 00:03:40.426 align:middle
The routing-controller-response
flow is the first half

00:03:40.426 --> 00:03:43.106 align:middle
of Symfony, and we've got it crossed off.

00:03:43.246 --> 00:03:45.086 align:middle
Now, let's dive into the second half.

