@@ -8,6 +8,8 @@ To *set* a flash message, before redirecting, call `$this->addFlash()` and pass,
8
8
in this situation, ` success ` . For the second argument, put the message that you
9
9
want to show to the user, like ` Vote counted! ` .
10
10
11
+ [[[ code('9733851b63') ]]]
12
+
11
13
The ` success ` key could be anything... it's kind of like a "category" for the flash
12
14
message... and you'll see how we use that in a minute.
13
15
@@ -28,12 +30,16 @@ one called `app.flashes`. Pass *this* the *category* (in our case,`success`). As
28
30
I mentioned, this could be * anything* . If you put ` dinosaur ` as the key in a controller,
29
31
then you'd read the ` dinosaur ` messages out * here* . Finish with ` {% endfor %} ` .
30
32
33
+ [[[ code('ca33c9b940') ]]]
34
+
31
35
Typically, you'll only have * one* success message in your flash at a time, but
32
36
* technically* you can have multiple. That's why we're looping over them.
33
37
34
38
Inside of this, render a ` <div> ` with ` class="alert alert-success" ` so it looks
35
39
like a * happy* message. Then, print out ` message ` .
36
40
41
+ [[[ code('23490be0be') ]]]
42
+
37
43
So if this works correctly, it will read all of our ` success ` flash messages and
38
44
render them. And once they've been read, Symfony will * remove* them so that they
39
45
won't render again on the * next* page load. By putting this in the base template,
@@ -52,9 +58,13 @@ things organized, create a new `public function` called `upVote()` and return `v
52
58
Inside, say ` $this->votes++ ` . Copy that, and create a * second* method which we'll
53
59
call - you guessed it - ` downVote() ` ... with ` $this->votes-- ` .
54
60
61
+ [[[ code('f6a52d95fb') ]]]
62
+
55
63
Thanks to these methods, in ` MixController ` , instead of having ` $mix->setVotes() `
56
64
set to ` $mix->getVotes() + 1 ` , we can just say ` $mix->upVote() ` ... and ` $mix->downVote() ` .
57
65
66
+ [[[ code('49312b26a8') ]]]
67
+
58
68
Now * that's* nice. Our controller reads much more clearly, and we've encapsulated
59
69
the ` upVote() ` and ` downVote() ` logic * into* our entity. If we head over and refresh,
60
70
it * still* works.
0 commit comments