Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c9e7980

Browse files
committed
Add code blocks to chapter: ep3-doctrine
1 parent d0cd5bc commit c9e7980

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

sfcasts/ep3-doctrine/rich-model.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ To *set* a flash message, before redirecting, call `$this->addFlash()` and pass,
88
in this situation, `success`. For the second argument, put the message that you
99
want to show to the user, like `Vote counted!`.
1010

11+
[[[ code('9733851b63') ]]]
12+
1113
The `success` key could be anything... it's kind of like a "category" for the flash
1214
message... and you'll see how we use that in a minute.
1315

@@ -28,12 +30,16 @@ one called `app.flashes`. Pass *this* the *category* (in our case,`success`). As
2830
I mentioned, this could be *anything*. If you put `dinosaur` as the key in a controller,
2931
then you'd read the `dinosaur` messages out *here*. Finish with `{% endfor %}`.
3032

33+
[[[ code('ca33c9b940') ]]]
34+
3135
Typically, you'll only have *one* success message in your flash at a time, but
3236
*technically* you can have multiple. That's why we're looping over them.
3337

3438
Inside of this, render a `<div>` with `class="alert alert-success"` so it looks
3539
like a *happy* message. Then, print out `message`.
3640

41+
[[[ code('23490be0be') ]]]
42+
3743
So if this works correctly, it will read all of our `success` flash messages and
3844
render them. And once they've been read, Symfony will *remove* them so that they
3945
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
5258
Inside, say `$this->votes++`. Copy that, and create a *second* method which we'll
5359
call - you guessed it - `downVote()`... with `$this->votes--`.
5460

61+
[[[ code('f6a52d95fb') ]]]
62+
5563
Thanks to these methods, in `MixController`, instead of having `$mix->setVotes()`
5664
set to `$mix->getVotes() + 1`, we can just say `$mix->upVote()`... and `$mix->downVote()`.
5765

66+
[[[ code('49312b26a8') ]]]
67+
5868
Now *that's* nice. Our controller reads much more clearly, and we've encapsulated
5969
the `upVote()` and `downVote()` logic *into* our entity. If we head over and refresh,
6070
it *still* works.

0 commit comments

Comments
 (0)