@@ -12,16 +12,16 @@ Open up `src/Controller/AdminController.php`, and in the `newStarshipPart()`
1212method, right below the form object, add ` $form->handleRequest() ` .
1313
1414To pull this off, we need to pass the current request object to this
15- method. You're familiar with this by now. Inject a ` $request ` from
16- HTTP Foundation as a method argument and pass the ` $request ` to this
17- method . You might be wondering what this ` handleRequest() ` is all about.
15+ method. You're familiar with this by now. Inject ` Request ` from the
16+ HTTP Foundation as the method argument ` $request ` and pass it to
17+ ` handleRequest() ` . You might be wondering what this ` handleRequest() ` is all about.
1818It simply grabs the submitted data from the request, applies that data to
1919your form, and now your form contains the user's submitted values.
2020
2121## Checking Form Submission
2222
23- Next, we want to know whether the form has actually been submitted or we just
24- load the form page. That's a breeze — just write ` if ($form->isSubmitted()) ` .
23+ Next, we want to know whether the form has actually been submitted or if we just
24+ loaded the form page. That's a breeze — just write ` if ($form->isSubmitted()) ` .
2525Then within that ` if ` , we can retrieve the submitted data with ` $form->getData() ` .
2626
2727Since our form type has a ` data_class ` option set to ` StarshipPart::class ` ,
@@ -32,7 +32,7 @@ variable and below `dd($part)`.
3232
3333## Testing Our Form
3434
35- Back in the browser, I'll quickly fill in the form. Hit create to submit it
35+ Back in the browser, I'll quickly fill in the form. Hit create to submit it...
3636and voila, a shiny new ` StarshipPart ` object with the data we sent. Notice
3737that no ID is set because Doctrine hasn't saved it in the database yet.
3838I'll quickly add a PHPDoc above the variable to make PhpStorm's autocomplete
@@ -42,11 +42,11 @@ happier, and delete the `dd()` statement.
4242
4343To save the new part, we need Doctrine's ` EntityManager ` . Inject it with
4444` EntityManagerInterface $entityManager ` in the method signature. Then, back
45- in the ` if ` , add ` $entityManager->persist($part ) ` , passing the ` $part `
45+ in the ` if ` , add ` $entityManager->persist() ` , passing the ` $part `
4646object and next ` $entityManager->flush() ` .
4747
4848Back to the browser, I'll set the name to: "Legacy Hyperdrive".
49- Give it a fair price, and don’t forget about important note:
49+ Give it a fair price, and don’t forget about an important note:
5050
5151> Be careful with high revs!
5252
@@ -64,10 +64,10 @@ shown exactly once. They are perfect for things like:
6464
6565If you peek into ` templates/base.html.twig ` You'll see we already have code
6666that loops over flash messages and renders them with nice styling depending
67- on the type: success, warning, error, default. After saving the entity to the
68- database, let's write this : ` $this->addFlash() `
67+ on the type: success, warning, error, default. Back in our controller,
68+ after saving the part entity to the database, write: ` $this->addFlash() `
6969
70- First argument: the message “ type” - it helps to control styling. Write
70+ First argument: the message " type" - it helps to control styling. Write
7171` success ` here. Second argument: the content of the message. How about
7272` sprintf('The part "%s" was created.', $part->getName()) ` .
7373
@@ -79,7 +79,7 @@ process with a redirect. This is a classic best practice for POST forms.
7979Let's return ` $this->redirectToRoute() ` .
8080
8181We can redirect anywhere, but I'll send users back to the part list for
82- convenience. It should be ` app_part_index ` route name .
82+ convenience. This route name is ` app_part_index ` .
8383
8484## Testing the Overall Flow
8585
@@ -88,7 +88,7 @@ name, set a price, and for notes, I'll say:
8888
8989> Do not exceed 120% core flux
9090
91- OK, submit the form again, and there it is. Our success flash message,
91+ OK, submit the form again, and there it is. Our flash message,
9292announcing that the part quantum reactor was successfully created. And if I
9393try to refresh the page, the message is gone, so it was shown only once,
9494and Chrome does not ask me if I want to resubmit the form again, so it was
0 commit comments