WEBVTT

NOTE Created by CaptionSync from Automatic Sync Technologies www.automaticsync.com

00:00:01.056 --> 00:00:04.426 align:middle
We've got a big project today,
a site about movies.

00:00:04.706 --> 00:00:07.406 align:middle
But only movies that have Samuel L. Jackson.

00:00:08.126 --> 00:00:09.646 align:middle
We'll start by creating a MovieController.

00:00:10.176 --> 00:00:11.826 align:middle
We could right click on the
Controller directory,

00:00:11.826 --> 00:00:14.156 align:middle
go to new, and select file from the menu.

00:00:14.246 --> 00:00:15.916 align:middle
But we can be faster!

00:00:16.226 --> 00:00:20.306 align:middle
For Mac users, use  +N
to get the "new" menu open.

00:00:20.306 --> 00:00:22.246 align:middle
And because we have the Symfony Plugin,

00:00:22.396 --> 00:00:25.186 align:middle
by typing 'controller' you'll find
an option to create one directly.

00:00:26.026 --> 00:00:28.836 align:middle
Let's keep things simple and
obvious and call it MovieController.

00:00:30.536 --> 00:00:34.836 align:middle
Ah, and when you use Git, PHPStorm asks you
whether you want to add new files to git.

00:00:35.076 --> 00:00:39.286 align:middle
I prefer to just do this
myself so I'll click 'no'.

00:00:40.016 --> 00:00:40.866 align:middle
Beautiful!

00:00:41.796 --> 00:00:46.166 align:middle
We'll need a route to this MovieController,
so add some annotations above indexAction().

00:00:47.096 --> 00:00:50.046 align:middle
Let's change these to @Route and
let autocomplete do its thing.

00:00:50.976 --> 00:00:53.776 align:middle
The one we want is
Sensio\Bundle\FrameworkExtraBundle

00:00:53.776 --> 00:00:58.046 align:middle
Configuration\Route, select that option and hit
tab and notice that it added a use statement

00:00:58.046 --> 00:01:02.246 align:middle
on line 5: That's really important
because when you use annotations you need

00:01:02.246 --> 00:01:03.586 align:middle
to have a use statement for them.

00:01:04.046 --> 00:01:06.506 align:middle
Now instead of spending your time
looking it up in the documentation,

00:01:06.506 --> 00:01:08.256 align:middle
autocomplete will take care of it for you.

00:01:08.756 --> 00:01:09.406 align:middle
Robots FTW!

00:01:09.406 --> 00:01:16.936 align:middle
Let's have our path be /movies/new and
change indexAction() to newAction()

00:01:17.136 --> 00:01:19.756 align:middle
because this controller will
render a "new movie" form.

00:01:20.696 --> 00:01:25.016 align:middle
And we'll fix up our render call in a
second: Head over to the browser and check

00:01:25.016 --> 00:01:26.876 align:middle
if our new route is hitting our endpoint.

00:01:28.776 --> 00:01:32.036 align:middle
Perfect! It can't find the
template but that's fine because,

00:01:32.036 --> 00:01:35.906 align:middle
there isn't one :) Annotations
have a lot of options

00:01:35.996 --> 00:01:38.966 align:middle
and one of them here is called
name, which auto-completes for us.

00:01:39.176 --> 00:01:39.856 align:middle
Hey thanks.

00:01:40.916 --> 00:01:45.306 align:middle
Fill that in with movies_new:
If you're the curious sort

00:01:45.306 --> 00:01:49.456 align:middle
and are wondering what other options you have,
just hold the control key and hit the space bar:

00:01:49.816 --> 00:01:52.626 align:middle
that will bring up all the
options that you have in that spot.

00:01:53.076 --> 00:01:55.966 align:middle
In fact, "control+space" can
be used pretty much anywhere

00:01:55.966 --> 00:01:59.686 align:middle
to show you your auto-complete
option - really handy.

00:02:00.886 --> 00:02:02.706 align:middle
This autocomplete works for two reasons.

00:02:02.976 --> 00:02:05.986 align:middle
First, an annotation represents a real class.

00:02:07.476 --> 00:02:09.546 align:middle
Hold command, or control if you're in windows,

00:02:09.546 --> 00:02:12.356 align:middle
and click @Route to open
up the class that fuels it.

00:02:12.356 --> 00:02:17.686 align:middle
If you hold command again and go into
its base class, you'll see that all

00:02:17.686 --> 00:02:23.126 align:middle
of those options are represented as properties
inside of that class: To take this further

00:02:23.126 --> 00:02:26.936 align:middle
if you go back to MovieController you can
hold command and click on the name option

00:02:26.936 --> 00:02:29.056 align:middle
and have it take you right to that property.

00:02:29.896 --> 00:02:32.746 align:middle
You may not need this very
often, but sometimes it's useful

00:02:32.746 --> 00:02:37.886 align:middle
to see how an annotation option is used to
figure out what value you want to set for it.

00:02:37.886 --> 00:02:42.806 align:middle
Now thanks to the annotations plugin,
annotations act a lot more like normal code,

00:02:42.926 --> 00:02:45.246 align:middle
with fancy auto-completion and other goodies.

