WEBVTT

NOTE Created by CaptionSync from Automatic Sync Technologies www.automaticsync.com

00:00:01.176 --> 00:00:05.596 align:middle
Since we have this new movie form, we're going
to want to save the data to the database.

00:00:06.876 --> 00:00:09.016 align:middle
To do this let's create a Movie entity.

00:00:09.016 --> 00:00:13.666 align:middle
I'm not going to generate it, let's just do this

00:00:13.666 --> 00:00:17.376 align:middle
by creating a good ole fashioned
PHP Class called Movie.

00:00:18.536 --> 00:00:21.616 align:middle
But when I do this, notice
the namespace box is empty.

00:00:22.026 --> 00:00:27.206 align:middle
I could type AppBundle\Entity here, but I'm
trying to do as little work as possible people!

00:00:28.506 --> 00:00:30.076 align:middle
Let's make the robots do this for you.

00:00:30.076 --> 00:00:34.176 align:middle
Go into preferences, search for 'directories'

00:00:34.306 --> 00:00:39.376 align:middle
and here you can see the three
directories that we excluded earlier.

00:00:41.906 --> 00:00:45.946 align:middle
Click on src and click the
blue sources button above.

00:00:46.206 --> 00:00:51.356 align:middle
Now we can see this on the right and clicking
the little 'p' allows us to edit the properties.

00:00:51.356 --> 00:00:54.416 align:middle
So, if we were using PSR-4 inside

00:00:54.416 --> 00:00:59.456 align:middle
of this directory we could actually put our
namespace prefix in this box - like KnpU.

00:01:01.636 --> 00:01:04.776 align:middle
But all we needed to do was mark it
as a source route, so we're done!

00:01:07.706 --> 00:01:11.326 align:middle
When we head back, oh look the
Entity directory disappeared!

00:01:11.726 --> 00:01:13.526 align:middle
Where did we misplace that to?

00:01:14.626 --> 00:01:17.296 align:middle
Well, sometimes PHPStorm does
that to empty directories.

00:01:17.506 --> 00:01:23.606 align:middle
Temporarily I'll switch back to project
view and now create a new PHP Class.

00:01:28.406 --> 00:01:31.966 align:middle
Because of the sources change, it
guesses the namespace part perfect.

00:01:33.076 --> 00:01:39.756 align:middle
Call the class Movie: Okay switch
back to Project Files and there it is.

00:01:39.956 --> 00:01:40.606 align:middle
Excellent!

00:01:40.746 --> 00:01:45.376 align:middle
In a second we'll set this up with
some annotations, but right now I want

00:01:45.376 --> 00:01:47.086 align:middle
to use it inside of my MovieController.

00:01:48.906 --> 00:01:53.226 align:middle
We'll add a form here soon, and when
we do, we'll need a new Movie object.

00:01:53.536 --> 00:01:56.436 align:middle
So we'll say $movie = new...

00:01:56.756 --> 00:02:02.746 align:middle
and I could end this with AppBundle\Entity\Movie
-- but you really don't want to do that.

00:02:02.746 --> 00:02:09.196 align:middle
Always go directly to the last part: in our
case Movie, and let that autocomplete: Because,

00:02:09.196 --> 00:02:13.776 align:middle
when you do that, it adds the use
statement on line 5 which is HUGE.

00:02:14.166 --> 00:02:16.936 align:middle
If you are not using the
autocomplete functionality

00:02:16.936 --> 00:02:19.326 align:middle
for use statements, then you're doing it wrong.

00:02:20.276 --> 00:02:24.976 align:middle
Now, if something went wrong and you didn't
autocomplete or you end up with Movie here

00:02:24.976 --> 00:02:27.806 align:middle
but no use statement, you
can import it if you want.

00:02:29.736 --> 00:02:31.636 align:middle
Just hit alt + enter.

00:02:32.296 --> 00:02:35.866 align:middle
Alt enter is one of the most
important shortcut we are going to see.

00:02:36.086 --> 00:02:37.686 align:middle
It's called the "actions" shortcut.

00:02:37.916 --> 00:02:40.286 align:middle
Often when you're inside some code.

00:02:40.286 --> 00:02:43.706 align:middle
you can alt + enter and get
a list of actions to do.

00:02:44.496 --> 00:02:48.416 align:middle
I'll select 'import class' from this list
and it will add that use statement for us.

00:02:48.606 --> 00:02:53.916 align:middle
To take this a bit further let's
add a public function listAction()

00:02:53.916 --> 00:02:55.926 align:middle
that will list those movies from the database.

00:02:56.116 --> 00:03:01.646 align:middle
I don't want to build this out now, I just want
it to return a simple Response that says "todo".

00:03:02.006 --> 00:03:07.016 align:middle
So let's add return new Response
and select the Response we want,

00:03:07.266 --> 00:03:09.986 align:middle
which is the one from HttpFoundation.

00:03:10.446 --> 00:03:14.336 align:middle
Hit tab and the use statement politely
puts itself on top of our file.

00:03:15.076 --> 00:03:18.766 align:middle
Finish with 'TODO'.

00:03:18.766 --> 00:03:26.786 align:middle
Now let's add a route above this,
@Route("/movies", name="movies_list"):

00:03:27.996 --> 00:03:32.386 align:middle
Oh and now that we have this second
endpoint, back in new.html.twig,

00:03:32.386 --> 00:03:34.466 align:middle
if we want to create a link
to this page, we can.

00:03:34.986 --> 00:03:37.526 align:middle
And we can use another live template.

00:03:37.786 --> 00:03:44.176 align:middle
Type a, hit tab, and use {{
path() }} and - amazingly -

00:03:44.176 --> 00:03:46.456 align:middle
we even get auto-complete on the route name.

00:03:46.566 --> 00:03:51.646 align:middle
For the link text, say "back
to list': Refresh that,

00:03:51.646 --> 00:03:55.766 align:middle
and there's our link right back to our list.

00:03:56.046 --> 00:03:58.246 align:middle
Awesome! So, don't.

00:03:58.656 --> 00:04:00.386 align:middle
write. use statements.

00:04:02.306 --> 00:04:03.486 align:middle
ever.

