1
00:00:00,450 --> 00:00:06,210
So let's finish up this passage to make a reservation for form, and what we want to do is if someone

2
00:00:06,210 --> 00:00:14,540
tries to go to a reservation summary, I have to type the URL because there's no direct link to it.

3
00:00:15,450 --> 00:00:20,250
We want them to be redirected somewhere else on the site and to be given an error message.

4
00:00:20,250 --> 00:00:25,290
And that just stops things like search engines from trying to index this page, which they'll try to

5
00:00:25,290 --> 00:00:31,410
do, or from someone manually typing in the UFO and getting there and saying, well, there's no information

6
00:00:31,410 --> 00:00:33,240
to show, so why am I even seeing this page?

7
00:00:33,780 --> 00:00:39,450
So right now, because I stopped and restarted my application, which erased the session in our case,

8
00:00:39,690 --> 00:00:43,620
when I tried to go there, I get a blank screen and that's not ideal.

9
00:00:43,620 --> 00:00:45,270
We want something else to happen.

10
00:00:45,870 --> 00:00:52,050
So let's go back to our code and I want to look at our template data go file.

11
00:00:52,050 --> 00:00:56,580
And that's under internal in the folder called Where Is It?

12
00:00:57,090 --> 00:00:58,010
Under Models.

13
00:00:58,020 --> 00:00:59,520
It's called Template Data Dutko.

14
00:00:59,760 --> 00:01:06,090
And you remember a long time ago I put in these things flash warning and error and I said, we'll be

15
00:01:06,090 --> 00:01:08,790
using those later and we're going to use them later right now.

16
00:01:09,570 --> 00:01:15,480
So those actually are in our template data that's passed to every single page of our site, but we're

17
00:01:15,480 --> 00:01:16,220
not using them at all.

18
00:01:16,440 --> 00:01:22,320
So let's go back over to the render ago, which is under the render package in the internal folder.

19
00:01:23,040 --> 00:01:26,850
And let's look at this, this part where we add default data right here.

20
00:01:26,880 --> 00:01:31,050
I am going to populate those three things right in here.

21
00:01:31,200 --> 00:01:35,460
Every time my page is rendered, we're going to populate them and we're not going to manually type things

22
00:01:35,460 --> 00:01:35,700
in.

23
00:01:36,570 --> 00:01:40,530
We're going to take advantage of our session so we can do that as follows.

24
00:01:40,710 --> 00:01:41,870
Tag flash.

25
00:01:42,540 --> 00:01:47,160
And that will be a success message or a message, a messages that appears once and then is automatically

26
00:01:47,160 --> 00:01:49,590
taken out of the session, which is exactly what we want.

27
00:01:50,250 --> 00:01:54,750
We're going to pull this out of the session and we have access to our app variable right here so we

28
00:01:54,750 --> 00:01:57,180
can get our session by going out session.

29
00:01:57,660 --> 00:02:01,020
And no, I'm not going to use, get or put.

30
00:02:01,290 --> 00:02:06,120
I'm going to use pop string, which is again built into our sessions package.

31
00:02:06,390 --> 00:02:07,830
And this is a really useful one.

32
00:02:08,190 --> 00:02:13,680
This will put something in the session until the next time a page is displayed and then it's taken out

33
00:02:13,680 --> 00:02:14,400
automatically.

34
00:02:14,550 --> 00:02:18,570
So it's the perfect place to put messages we want to send to our user.

35
00:02:18,900 --> 00:02:20,550
So I'm going to put that in there pop string.

36
00:02:20,550 --> 00:02:22,350
And it requires a couple of arguments.

37
00:02:22,350 --> 00:02:24,240
The context ARG context.

38
00:02:24,240 --> 00:02:25,620
Well, I don't do I have the context?

39
00:02:26,310 --> 00:02:26,730
There it is.

40
00:02:26,730 --> 00:02:27,960
Yes, I do have the context.

41
00:02:28,320 --> 00:02:33,000
So ARG context and it also requires a name flash.

42
00:02:33,330 --> 00:02:37,830
Since this is a flash variable, that's what I'm going to be calling it.

43
00:02:37,980 --> 00:02:43,830
I'll just call a flash and I'll do the same thing for warning and the same thing for error.

44
00:02:44,250 --> 00:02:50,250
So Teda Error and TDF warning and I'll call error.

45
00:02:50,970 --> 00:02:55,310
Error seems like a good name and I'll call warning warning, which seems like a good name.

46
00:02:55,620 --> 00:02:59,190
So those will automatically be populated any time.

47
00:02:59,610 --> 00:03:07,200
I am rendering a page now back in my handlers, let's change this part that says if not OK.

48
00:03:07,200 --> 00:03:11,880
And remember that this is when we're trying to pull a sessional variable named reservation out of the

49
00:03:11,880 --> 00:03:15,630
session and to type cast it to models reservation.

50
00:03:15,840 --> 00:03:18,420
If that doesn't work, that means one of two things.

51
00:03:18,420 --> 00:03:24,720
Either there's no such and variable data at all or there's no variable called reservation in the session

52
00:03:24,930 --> 00:03:30,860
or the value that's in the session that happens to be name reservation can't be cast to a model reservation,

53
00:03:30,870 --> 00:03:34,140
whatever the case may be, I definitely want to take them somewhere else.

54
00:03:34,470 --> 00:03:40,020
So I'll leave the log file there for now, but I'll now pass a value into our session.

55
00:03:40,020 --> 00:03:43,050
Emden app session put.

56
00:03:44,740 --> 00:03:55,510
And I want to put from context, I will put a value called Okkult error, because this is an error and

57
00:03:55,510 --> 00:03:56,260
I'll give it a value.

58
00:03:56,260 --> 00:04:02,860
And the error I want to put in there is I can't get a reservation from session, which isn't a great

59
00:04:02,860 --> 00:04:05,020
error message, but it's sufficient for our purposes.

60
00:04:05,200 --> 00:04:07,660
So I've now popped that value in there.

61
00:04:08,140 --> 00:04:11,130
And I don't know because it's still just returning an empty page.

62
00:04:11,140 --> 00:04:13,120
So I need to do an HTTP redirect.

63
00:04:13,270 --> 00:04:14,710
Where shall I take the oil issue?

64
00:04:14,710 --> 00:04:23,200
Topdog redirect and I'll just take them to the homepage and I'll give the status http status temporary

65
00:04:23,200 --> 00:04:23,620
redirect.

66
00:04:23,620 --> 00:04:28,600
This time it has to be in the 300 range for a redirect and a temporary redirect is perfect because maybe

67
00:04:28,600 --> 00:04:32,260
they're going to make a reservation, maybe they'll come back here, whatever the case may be, that

68
00:04:32,260 --> 00:04:33,930
is sufficient for our purposes.

69
00:04:34,510 --> 00:04:36,790
So this technically should work now.

70
00:04:36,790 --> 00:04:40,210
We're not going to do anything with that sectional variable yet, but let's just make sure it actually

71
00:04:40,230 --> 00:04:41,170
takes us to the homepage.

72
00:04:41,170 --> 00:04:47,380
So I'll stop the application, start the application that clears everything out and compiles in my changes.

73
00:04:47,650 --> 00:04:52,210
And I'll try just to load this page by doing this and it takes me back.

74
00:04:52,220 --> 00:04:55,950
So it did redirect me to the home page, but it didn't display the error.

75
00:04:56,260 --> 00:04:59,950
So how do I get the error message displayed?

76
00:04:59,950 --> 00:05:00,820
I want to use Nottie.

77
00:05:00,850 --> 00:05:04,740
I want an error message to show up here displaying whatever my error message is.

78
00:05:05,170 --> 00:05:07,300
Well, let's go back to base left.

79
00:05:08,020 --> 00:05:09,190
Let's find that file.

80
00:05:11,190 --> 00:05:15,870
Which is under my code and it's under my templates and it's called base.

81
00:05:16,620 --> 00:05:17,550
So let's find that.

82
00:05:17,910 --> 00:05:23,570
And remember, in this base layout file, we have a bunch of JavaScript that appears on every page.

83
00:05:23,580 --> 00:05:28,110
And this is exactly the situation where I want to handle every possibility.

84
00:05:28,110 --> 00:05:34,800
Every time a user is displayed a page, if there's an error message or a success message or a warning,

85
00:05:34,800 --> 00:05:36,050
I want that to be displayed.

86
00:05:36,060 --> 00:05:38,480
So we'll just worry about success and error for right now.

87
00:05:38,760 --> 00:05:44,610
So let's put those in here and I'll put them right after these two things.

88
00:05:44,640 --> 00:05:48,540
After our notify and notify Motal, I'll create another thing.

89
00:05:48,570 --> 00:05:54,240
Now, what I want to have happen is when someone comes to a page and I need to display an error message,

90
00:05:54,480 --> 00:05:58,710
I want to actually call success.

91
00:05:58,750 --> 00:06:00,030
I want to call it error message.

92
00:06:00,030 --> 00:06:05,870
So I could just do it like this notify, which is right up here.

93
00:06:05,880 --> 00:06:08,850
We've already done this and notify takes two arguments.

94
00:06:08,850 --> 00:06:15,450
It takes a message and a message type and the message will be whatever I get from some value.

95
00:06:15,450 --> 00:06:17,370
So I'll just put a dot there right now as a placeholder.

96
00:06:17,400 --> 00:06:19,130
Actually, that needs to be in quotation marks.

97
00:06:19,680 --> 00:06:24,720
So it's delete this and dot and we'll get that dot populated in a minute.

98
00:06:24,960 --> 00:06:27,620
And the second argument is the message type.

99
00:06:27,630 --> 00:06:29,550
And in this case it happens to be an error.

100
00:06:30,600 --> 00:06:36,260
Now how do I get that dot which in Goldwing template syntax means some kind of data.

101
00:06:36,270 --> 00:06:40,470
I get it like this with and dot here.

102
00:06:42,120 --> 00:06:48,460
And end, which is a shorthand, it says if you have some value in error, that's not empty.

103
00:06:48,840 --> 00:06:49,560
Do this with it.

104
00:06:50,340 --> 00:06:53,040
So it's like an estimate and that will display it if there's an error.

105
00:06:53,460 --> 00:06:55,070
Now, what if I have a success message?

106
00:06:55,080 --> 00:06:56,880
Well, that's stored in a value called flash.

107
00:06:57,150 --> 00:07:00,890
So with Flash and this time it's type success.

108
00:07:02,550 --> 00:07:12,570
So if I start my application and run it again and go back to my Web browser and manually type in the

109
00:07:12,930 --> 00:07:20,070
reservation summary right there and hit it, it partly back and it gave me my error message and that's

110
00:07:20,070 --> 00:07:22,270
exactly what I want to have happen.

111
00:07:23,040 --> 00:07:24,340
So that's really convenient.

112
00:07:24,390 --> 00:07:31,080
Now we could of course, we haven't done that, but if we do one for warning as well, can we do that?

113
00:07:31,110 --> 00:07:31,800
Sure, why not?

114
00:07:31,830 --> 00:07:36,020
We already have a warning so we can copy this, paste it here.

115
00:07:36,030 --> 00:07:36,690
We may as well do it.

116
00:07:36,690 --> 00:07:42,060
Now with Flash becomes with warning, notify, warning.

117
00:07:43,860 --> 00:07:45,060
Let's just make sure that works.

118
00:07:45,330 --> 00:07:46,140
It should compile.

119
00:07:46,140 --> 00:07:48,360
If there's an error, the template won't compile.

120
00:07:49,380 --> 00:07:50,580
So, so far so good.

121
00:07:50,670 --> 00:07:51,590
So let's try it again.

122
00:07:55,380 --> 00:07:56,380
Reservation summary.

123
00:07:57,210 --> 00:07:57,820
And there it is.

124
00:07:57,870 --> 00:07:59,960
OK, so everything compiled, so it works well.

125
00:07:59,970 --> 00:08:05,690
So now I have a means of getting information to my users in the form of an unobtrusive alert.

126
00:08:05,910 --> 00:08:07,470
That's really quite helpful.

127
00:08:07,480 --> 00:08:10,260
And there's one more thing I want to do, and it's a really simple thing.

128
00:08:10,260 --> 00:08:12,620
We've left our reservation in the session.

129
00:08:12,900 --> 00:08:19,290
So when I come back here to my code and look at my handlers, what I'm talking about is this let me

130
00:08:19,290 --> 00:08:20,010
just hide this.

131
00:08:20,820 --> 00:08:29,820
So back in my handlers, when I post wherever that is right here, I posted to my session or I put in

132
00:08:29,820 --> 00:08:34,430
my session then with the name of reservation, the value of this reservation.

133
00:08:34,740 --> 00:08:38,570
Well, once the reservation is complete, that really should be taken out of the session.

134
00:08:38,820 --> 00:08:40,170
So let's go back down here.

135
00:08:40,650 --> 00:08:42,120
We pull it out of the session here.

136
00:08:42,120 --> 00:08:43,250
We check for OK.

137
00:08:43,500 --> 00:08:46,500
And after we get that, we already have the value from the session.

138
00:08:46,500 --> 00:08:47,960
So we don't need it in there anymore.

139
00:08:47,970 --> 00:08:50,820
So let's get rid of it and update session.

140
00:08:51,120 --> 00:08:54,570
And there's got to be a method that says, get it out of here and there it is.

141
00:08:54,570 --> 00:08:55,120
Remove.

142
00:08:55,740 --> 00:09:05,840
So removing using our context, which is right here, and just give the name it has and that is reservation.

143
00:09:06,630 --> 00:09:12,120
So with that, we can actually remove data from our reservation and that is quite helpful.

144
00:09:13,410 --> 00:09:15,390
OK, that's it for this section.

145
00:09:15,390 --> 00:09:19,230
In the next section, we're going to move on to testing because we talked about testing really early

146
00:09:19,230 --> 00:09:22,860
in the course, but we haven't actually written any tests for our code.

147
00:09:22,860 --> 00:09:24,390
That's going to be our final project.

148
00:09:24,660 --> 00:09:27,000
So we'll devote the next few sessions to that.
