1
00:00:10,086 --> 00:00:10,246
>> Alright.

2
00:00:10,246 --> 00:00:12,156
Welcome back to Computer
Science S75.

3
00:00:12,506 --> 00:00:16,136
So tonight's on MVC and
XML in the context of PHP,

4
00:00:16,136 --> 00:00:17,996
and we'll also talk
a bit tonight

5
00:00:17,996 --> 00:00:21,616
about the first project Zero
whose PDF Spec is now online,

6
00:00:21,616 --> 00:00:23,386
and we'll also talk
about the CS50 appliance

7
00:00:23,636 --> 00:00:28,336
and about the Linux and about
a lamp stack more generally.

8
00:00:28,336 --> 00:00:33,426
So, what was MVC from last week?

9
00:00:34,526 --> 00:00:40,096
What was the purpose
served by MVC?

10
00:00:40,766 --> 00:00:43,316
What does MVC stand for?

11
00:00:43,316 --> 00:00:44,116
I'll take anything.

12
00:00:44,176 --> 00:00:45,096
Yeah. Connor.

13
00:00:45,196 --> 00:00:45,916
>> Model View Controller.

14
00:00:46,186 --> 00:00:46,416
>> Sorry.

15
00:00:46,796 --> 00:00:47,726
>> Model View Controller.

16
00:00:47,726 --> 00:00:48,796
>> Okay. Model View Controller.

17
00:00:48,796 --> 00:00:49,806
Good. So someone else.

18
00:00:49,806 --> 00:00:50,506
What does that mean?

19
00:00:50,506 --> 00:00:52,356
And what was the point of
introducing this acronym?

20
00:00:52,356 --> 00:00:52,426
Yeah.

21
00:00:52,696 --> 00:00:54,366
>> It means dividing
all your files

22
00:00:54,426 --> 00:00:56,046
up into different
stacks and layers...

23
00:00:56,236 --> 00:00:56,506
>> Okay.

24
00:00:56,596 --> 00:00:59,606
>> and getting things you
use for example more often,

25
00:00:59,606 --> 00:01:02,106
single source and then
using it in multiple views.

26
00:01:03,346 --> 00:01:04,246
>> Okay. Good.

27
00:01:04,246 --> 00:01:08,126
So reusing of code is one
of the motivations for MVC.

28
00:01:08,126 --> 00:01:10,996
Views recall had to do with
the display of information,

29
00:01:10,996 --> 00:01:13,886
and so you could share code
among your views, particularly

30
00:01:13,886 --> 00:01:16,446
for headers and for footers,
and we didn't really dive

31
00:01:16,446 --> 00:01:20,156
into much detail yet about
controllers, or models, even,

32
00:01:20,366 --> 00:01:22,576
so today we'll look a little
more at the first two,

33
00:01:22,576 --> 00:01:25,936
views and controllers so that
you have some possible design

34
00:01:25,936 --> 00:01:28,146
patterns in mind when
you tackle project Zero.

35
00:01:28,146 --> 00:01:30,796
And also in tonight's section,
which will focus predominantly

36
00:01:30,796 --> 00:01:33,486
on project Zero, you'll be given
some direction and some tips

37
00:01:33,776 --> 00:01:35,656
on what to do for that project.

38
00:01:35,656 --> 00:01:39,006
So just to set the stage,
project Zero is about pizza ML,

39
00:01:39,006 --> 00:01:40,086
Pizza Markup Language.

40
00:01:40,086 --> 00:01:41,726
And the motivation for
this is as follows.

41
00:01:42,226 --> 00:01:45,006
Some years ago there was a
favorite pizzeria of ours

42
00:01:45,006 --> 00:01:48,166
down the road, a shop called
Three Aces, and unfortunately,

43
00:01:48,316 --> 00:01:50,846
closed its shop, but
we hung on to its menu

44
00:01:50,846 --> 00:01:53,286
because it's a wonderful
example of a messy data set.

45
00:01:53,646 --> 00:01:55,266
And the goal for this project is

46
00:01:55,266 --> 00:01:58,546
to actually implement your
own ecommerce like website

47
00:01:58,546 --> 00:02:02,556
for this pizzeria with which
customers can order pizzas

48
00:02:02,556 --> 00:02:05,246
and subs and salads and
the like, but the fellow

49
00:02:05,246 --> 00:02:08,936
who owned this shop we've
hypothesized wasn't necessarily

50
00:02:08,936 --> 00:02:11,756
very technical and doesn't
really need the overkill

51
00:02:11,756 --> 00:02:15,216
of a full-fledged database like
MySQL or certainly not Oracle

52
00:02:15,216 --> 00:02:18,496
or the like, and in fact in
terms of updating the menu,

53
00:02:18,766 --> 00:02:21,696
he is fine with something
simple.

54
00:02:21,696 --> 00:02:24,816
Even using something simple
like text edit on a MAC

55
00:02:24,816 --> 00:02:27,996
or Notepad.exe on a PC.

56
00:02:27,996 --> 00:02:30,966
He also doesn't expect a
huge amount of traffic, too,

57
00:02:30,966 --> 00:02:32,586
so he wants to just be
able to run this site off

58
00:02:32,586 --> 00:02:36,036
of an old server that they were
given under the desk somewhere.

59
00:02:36,036 --> 00:02:39,816
So in short, resources
are few, the load is low,

60
00:02:39,816 --> 00:02:43,506
and so the motivation
then at hand is to come

61
00:02:43,506 --> 00:02:45,546
up with a database
design of sorts

62
00:02:45,546 --> 00:02:48,716
that can nonetheless support
a pizza ordering website.

63
00:02:48,716 --> 00:02:50,186
So tonight we'll talk about XML.

64
00:02:50,186 --> 00:02:53,656
XML is a text file format
similar in spirit to HTML

65
00:02:53,656 --> 00:02:55,136
but at the risk of
oversimplifying,

66
00:02:55,376 --> 00:02:59,056
it's like a make-your-own
HTML type language,

67
00:02:59,056 --> 00:03:00,726
where you create your own tags.

68
00:03:00,726 --> 00:03:03,416
You create your own attributes,
so this will be an opportunity

69
00:03:03,416 --> 00:03:04,916
to design your own
representation

70
00:03:04,916 --> 00:03:07,776
of this pizzeria's menu and
you'll have to implement

71
00:03:07,776 --> 00:03:10,966
in PHP a system whereby
users can visit this site

72
00:03:11,176 --> 00:03:14,816
and can navigate the menu and
can add things to their cart,

73
00:03:14,816 --> 00:03:16,336
change quantities,
delete things,

74
00:03:16,586 --> 00:03:17,996
and ultimately "check out."

75
00:03:18,126 --> 00:03:21,366
And all of this will require
some maintenance of state,

76
00:03:21,556 --> 00:03:24,636
so recall last week our
discussion of the session object

77
00:03:24,636 --> 00:03:26,536
in PHP and cookies
more generally.

78
00:03:26,536 --> 00:03:28,946
So being able to
store things from page

79
00:03:28,946 --> 00:03:32,786
to page will be crucial for this
particular challenge at hand.

80
00:03:32,786 --> 00:03:35,436
So more on that toward the end
of tonight's, but keep in mind

81
00:03:35,436 --> 00:03:37,606
that the goal will
indeed by this pizzeria.

82
00:03:37,796 --> 00:03:40,416
So what's the context in
which we're going to do this?

83
00:03:40,706 --> 00:03:43,506
So the CS50 appliance is
just a virtual machine.

84
00:03:43,666 --> 00:03:45,586
Per the announcement on
the course's home page,

85
00:03:45,586 --> 00:03:46,946
we're going to post
it very late tonight

86
00:03:46,946 --> 00:03:49,896
or by tomorrow morning once
we finish adding a few final

87
00:03:49,896 --> 00:03:52,886
touches to what's going
to be called version 17A

88
00:03:53,156 --> 00:03:55,706
and the directions for this
will be on the course's website.

89
00:03:55,706 --> 00:03:58,196
In the meantime, on the projects
page on the course's website,

90
00:03:58,236 --> 00:04:00,626
is the specification for
the, for the project.

91
00:04:00,626 --> 00:04:02,836
So you can dive in tonight
and think through it,

92
00:04:02,836 --> 00:04:04,406
read through it, and then
tomorrow you'll be able

93
00:04:04,406 --> 00:04:06,866
to download this and
dive in hands on.

94
00:04:07,166 --> 00:04:10,046
So the appliance
is a installation

95
00:04:10,226 --> 00:04:12,256
of a Linux flavor called Fedora.

96
00:04:12,256 --> 00:04:14,876
For those unfamiliar, Linux
exists in many different forms,

97
00:04:14,876 --> 00:04:17,906
Ubuntu, in Debian, in
Red Hat, in Centos,

98
00:04:17,906 --> 00:04:19,376
and all sorts of others.

99
00:04:19,626 --> 00:04:23,106
We happen to be using Fedora,
which is an RPM based system,

100
00:04:23,106 --> 00:04:25,176
but that's mostly
irrelevant for our purposes

101
00:04:25,176 --> 00:04:27,376
because what really matters
about the appliance is

102
00:04:27,376 --> 00:04:29,886
that it has LAMP,
and PHP, and Apache

103
00:04:30,096 --> 00:04:35,286
and MySQL all preinstalled
and configured for you

104
00:04:35,286 --> 00:04:38,186
but still you'll have root
access with which to tinker

105
00:04:38,186 --> 00:04:40,536
with the configuration files
we've talked about thus,

106
00:04:40,686 --> 00:04:44,516
httb.conf, php.ini, and
the like, and you'll find

107
00:04:44,516 --> 00:04:47,096
that it's a very natural
real world environment

108
00:04:47,256 --> 00:04:49,746
so that even though it's
running on your own laptop

109
00:04:49,746 --> 00:04:53,126
or desktop it's representative
of most any commercial host

110
00:04:53,396 --> 00:04:55,656
or VPS, virtual private server,

111
00:04:55,756 --> 00:04:57,546
that you yourself
might subscribe to.

112
00:04:57,546 --> 00:04:59,486
So you'll be able to experience
exactly what you would

113
00:04:59,486 --> 00:05:02,156
if you were actually paying
for some third-party hosting.

114
00:05:02,156 --> 00:05:04,096
So, we'll do some more
demos and I'll walk you

115
00:05:04,096 --> 00:05:05,786
through some commands
for those unfamiliar

116
00:05:05,986 --> 00:05:06,926
over the course of today.

117
00:05:07,356 --> 00:05:09,266
So here's a better picture
than I certainly drew

118
00:05:09,266 --> 00:05:11,846
with my ASCII art
last week, of MVC.

119
00:05:11,846 --> 00:05:14,966
And the idea ultimately between
MVC is that you have the brains

120
00:05:14,966 --> 00:05:17,156
of an operation known
as a controller,

121
00:05:17,156 --> 00:05:18,456
and it might be one controller,

122
00:05:18,456 --> 00:05:20,106
it might be multiple
controllers,

123
00:05:20,346 --> 00:05:23,986
and the controller talks
to things like a model.

124
00:05:23,986 --> 00:05:26,456
Now, for now, tonight,
we'll largely wave our hands

125
00:05:26,456 --> 00:05:28,966
at the model, but we'll come
back to this in the context

126
00:05:28,966 --> 00:05:32,026
of databases in particular,
but for now you can think

127
00:05:32,026 --> 00:05:36,926
of the model as being even for
something like your XML file,

128
00:05:37,026 --> 00:05:39,196
so more on that to come.

129
00:05:39,486 --> 00:05:41,926
And then Views is what
handles the actual aesthetics.

130
00:05:41,926 --> 00:05:45,666
So once you have, for
instance, come up with the data

131
00:05:45,666 --> 00:05:48,526
that you want to show to the
user, typically you pass it

132
00:05:48,526 --> 00:05:51,276
as one or more arguments to
this thing called a view,

133
00:05:51,486 --> 00:05:53,476
and the view is then rendered

134
00:05:53,516 --> 00:05:56,076
with that dynamically
provided data.

135
00:05:56,076 --> 00:05:58,406
And we'll see a couple more code
examples about this earlier,

136
00:05:58,636 --> 00:06:01,186
but really the key takeaway
here is the directions

137
00:06:01,186 --> 00:06:01,916
of these lines.

138
00:06:01,916 --> 00:06:04,446
There is no lateral
line left to write

139
00:06:04,646 --> 00:06:07,366
and the ideas will become
clear is that you're models,

140
00:06:07,366 --> 00:06:09,796
which again refer to
databases, real world entities,

141
00:06:09,796 --> 00:06:13,456
student objects, pizza objects,
order objects and the like,

142
00:06:13,906 --> 00:06:17,236
should not have any direct
communication with the display

143
00:06:17,236 --> 00:06:19,506
of that information, it's
really the controller

144
00:06:19,506 --> 00:06:22,546
that should query a database, or
even an XML file, get some data,

145
00:06:22,626 --> 00:06:25,666
store it in variables, then pass
those variables to the views

146
00:06:25,836 --> 00:06:27,726
for actual aesthetic rendering.

147
00:06:27,856 --> 00:06:31,236
And so we'll see again some
concrete examples here tonight,

148
00:06:31,236 --> 00:06:34,156
and we'll revisit this
topology over time.

149
00:06:34,546 --> 00:06:36,596
But first some preliminaries.

150
00:06:36,596 --> 00:06:40,706
How many people here have
used source control before,

151
00:06:40,706 --> 00:06:42,286
if you know what the
expression means?

152
00:06:43,036 --> 00:06:45,226
Okay. So a little bit of
this, a little over here.

153
00:06:45,226 --> 00:06:46,296
Okay, so a couple of you.

154
00:06:46,586 --> 00:06:48,876
We won't dwell too
much on this in lecture

155
00:06:48,876 --> 00:06:50,996
because the project
specification itself has some

156
00:06:50,996 --> 00:06:55,006
of the familiar commands, but
a source control is generally

157
00:06:55,006 --> 00:06:58,276
about keeping backups of
your files in the form

158
00:06:58,276 --> 00:07:01,476
of differentials, changes
from one version to another.

159
00:07:01,766 --> 00:07:03,656
If I put the question
this way, how many of you

160
00:07:03,656 --> 00:07:06,476
when writing essays, writing
resumes, writing any kinds

161
00:07:06,476 --> 00:07:09,186
of documents that you
want to make changes to,

162
00:07:09,186 --> 00:07:12,016
just so that you have
copies of the old version,

163
00:07:12,236 --> 00:07:15,956
change your file
from something.doc

164
00:07:16,296 --> 00:07:21,626
to something-hold.doc.,
or something-july1.doc,

165
00:07:21,626 --> 00:07:24,476
or something-july2.doc, right.

166
00:07:24,476 --> 00:07:26,456
We all have probably
adopted our own sort

167
00:07:26,456 --> 00:07:28,596
of versioning schemes
just by making copies

168
00:07:28,596 --> 00:07:29,796
of files and renaming them.

169
00:07:30,166 --> 00:07:31,746
But what's the downside
of this approach?

170
00:07:35,136 --> 00:07:35,236
Yeah.

171
00:07:35,696 --> 00:07:38,226
>> [Inaudible] rename
it [inaudible].

172
00:07:38,486 --> 00:07:41,446
>> Yeah. If you rename the file,
you lost some of its history

173
00:07:41,446 --> 00:07:43,996
and you can sort of figure
out what change you made

174
00:07:43,996 --> 00:07:46,886
between version 3 and version
4 by opening them both up side

175
00:07:46,886 --> 00:07:48,966
by side, but you the human
have to kind of figure

176
00:07:48,966 --> 00:07:50,976
out what changes did I make.

177
00:07:50,976 --> 00:07:53,466
If you're a bit more
advanced with Microsoft word,

178
00:07:53,466 --> 00:07:56,926
realize that it has a track
changes feature which allows you

179
00:07:56,926 --> 00:07:58,906
to keep one file, but record

180
00:07:58,906 --> 00:08:01,176
at least your most
recent changes history.

181
00:08:01,406 --> 00:08:03,176
That's similar in
spirit to source control,

182
00:08:03,176 --> 00:08:04,946
but if instead you've been
doing it the old school,

183
00:08:04,946 --> 00:08:07,216
sort of intuitive
approach of just recopying

184
00:08:07,216 --> 00:08:09,516
and renaming files, well
we can do better than this,

185
00:08:09,516 --> 00:08:11,066
particularly for large files.

186
00:08:11,066 --> 00:08:13,446
Because if you're making
a copy of a file just

187
00:08:13,446 --> 00:08:15,866
so that you keep a backup of it
around with a different name,

188
00:08:16,056 --> 00:08:18,926
you're literally duplicating all
of the data between those files,

189
00:08:18,926 --> 00:08:21,236
which might not be a big
deal for essays and whatnot,

190
00:08:21,476 --> 00:08:25,666
but if it's a video file or if
it's simply a very large essay

191
00:08:25,666 --> 00:08:27,416
with lots of diagrams
or pictures,

192
00:08:27,636 --> 00:08:30,706
you could start churning
through kilobytes or megabytes.

193
00:08:30,706 --> 00:08:31,586
So we can do better.

194
00:08:31,776 --> 00:08:33,846
So in the world of programming
there's this general notion

195
00:08:33,846 --> 00:08:36,256
of source control, which
refers to the ability

196
00:08:36,256 --> 00:08:39,126
to write a program, for
instance, Hello.php,

197
00:08:39,126 --> 00:08:42,026
and then if you want
to make a change to it,

198
00:08:42,206 --> 00:08:45,716
you can first commit the
current version of your code

199
00:08:46,006 --> 00:08:48,426
to what's called a
source code repository

200
00:08:48,866 --> 00:08:51,856
and that repository is
what essentially stores all

201
00:08:51,856 --> 00:08:54,466
of the backups that you
yourself have decided to commit.

202
00:08:54,786 --> 00:08:57,656
You never change the name, your
file always stays as Hello.PHP,

203
00:08:57,656 --> 00:09:03,336
but you can roll back in time
through certain commands to say,

204
00:09:03,336 --> 00:09:06,466
actually give me the version
from yesterday, or two days ago,

205
00:09:06,466 --> 00:09:09,946
or a month ago, and the
source control software

206
00:09:09,946 --> 00:09:12,586
that you're using figures
out how to do all of this.

207
00:09:12,586 --> 00:09:14,236
You don't do any of
the renamings yourself.

208
00:09:14,606 --> 00:09:18,786
So, the way, beyond the
motivation for this being just

209
00:09:18,786 --> 00:09:20,406
to clean up one's
backup systems,

210
00:09:20,646 --> 00:09:23,366
it's also very compelling for
people to collaborate on code.

211
00:09:23,366 --> 00:09:25,566
So even though for this
course you'll be working solo

212
00:09:25,566 --> 00:09:28,196
on your own on the projects,
it's not unreasonable to expect

213
00:09:28,196 --> 00:09:29,706
that you're eventually
going to work with a friend

214
00:09:29,706 --> 00:09:31,646
on some project, a
colleague on some project,

215
00:09:31,866 --> 00:09:34,116
and so what version control
also allows you to do is this.

216
00:09:34,526 --> 00:09:37,406
In general, this right hand
line here, the black one,

217
00:09:37,726 --> 00:09:39,816
represents what we'll
call a master branch.

218
00:09:39,816 --> 00:09:42,956
A master branch is like
the default repository

219
00:09:43,326 --> 00:09:46,136
into which everyone saves
their code on the team.

220
00:09:46,486 --> 00:09:50,696
But you don't want decide
some night that, "Oh, I'm,

221
00:09:50,696 --> 00:09:53,016
I'm going to want to try
implement some brand new feature

222
00:09:53,106 --> 00:09:56,156
for my code, and you
don't though think

223
00:09:56,156 --> 00:09:57,726
that it's just going
to take a few minutes.

224
00:09:57,726 --> 00:09:59,336
It could take an hour,
could take a day,

225
00:09:59,336 --> 00:10:00,606
could take a week, a month.

226
00:10:00,606 --> 00:10:03,386
So you don't necessarily
want to start writing changes

227
00:10:03,736 --> 00:10:06,586
and then pushing those
changes to the repository

228
00:10:06,776 --> 00:10:08,786
if your changes are
only partially complete.

229
00:10:08,786 --> 00:10:10,696
Right if your code is
broken, it's not going

230
00:10:10,696 --> 00:10:12,616
to really hurt you
but you don't want

231
00:10:12,616 --> 00:10:14,466
to break the entire
project for everyone else.

232
00:10:14,966 --> 00:10:17,126
So what source control
allows you to do is

233
00:10:17,126 --> 00:10:18,986
to fork off what's
called a branch.

234
00:10:18,986 --> 00:10:21,596
So on the left in yellow here is
what we might call a development

235
00:10:21,596 --> 00:10:24,296
branch and any developer,
yourself included,

236
00:10:24,456 --> 00:10:27,006
can create a separate branch,
which you can think of as a copy

237
00:10:27,066 --> 00:10:30,116
of the main repository, but you
can make all of your changes,

238
00:10:30,116 --> 00:10:33,456
you can push changes to the
server, but they stay separate,

239
00:10:33,626 --> 00:10:36,016
a separate branch of
the tree so to speak,

240
00:10:36,206 --> 00:10:38,206
and only once you have
decided you know what,

241
00:10:38,206 --> 00:10:41,046
I've finished this feature, I've
bug, I've correctness tested

242
00:10:41,046 --> 00:10:43,336
and everything is good, then
you want to merge it back

243
00:10:43,616 --> 00:10:45,226
into the so-called
master branch,

244
00:10:45,496 --> 00:10:47,776
then you can actually
do exactly that.

245
00:10:47,776 --> 00:10:50,256
Emerge from yellow to blue

246
00:10:50,346 --> 00:10:54,176
at which point everyone else
has access to your feature.

247
00:10:54,176 --> 00:10:57,186
So in short, not so applicable,
this branching for our purposes

248
00:10:57,186 --> 00:10:59,566
in the course since again you'll
be working solo, but that's

249
00:10:59,566 --> 00:11:00,716
yet another feature of this.

250
00:11:00,716 --> 00:11:03,346
So source code controls
incredibly common

251
00:11:03,346 --> 00:11:05,476
in the software world
these days, and perhaps one

252
00:11:05,476 --> 00:11:09,596
of the most popular tools is
something called GET these days.

253
00:11:09,596 --> 00:11:14,636
Now for those familiar,
Visual Studio in the Windows

254
00:11:14,636 --> 00:11:16,236
and World has source
control built in

255
00:11:16,236 --> 00:11:18,436
and it just comes
with visual studio.

256
00:11:18,746 --> 00:11:24,696
There are other tools out
there like CVS and RCS and SVN

257
00:11:25,076 --> 00:11:26,206
which you might have
heard before.

258
00:11:26,206 --> 00:11:28,236
All of those are
rather dated these days

259
00:11:28,236 --> 00:11:30,976
and rather what's gotten more
popular are things like get,

260
00:11:31,196 --> 00:11:34,366
and mercurial, and
bazaar, these are all tools

261
00:11:34,366 --> 00:11:36,646
that are distributed
source code tools,

262
00:11:36,896 --> 00:11:38,556
and what this simply means is

263
00:11:38,556 --> 00:11:42,456
that you have not only a central
server to save or to push all

264
00:11:42,456 --> 00:11:45,016
of your changes too, you
also have a local copy

265
00:11:45,016 --> 00:11:45,996
in your own directory.

266
00:11:46,186 --> 00:11:48,706
So it means you can save
different versions of your code

267
00:11:48,706 --> 00:11:52,456
in your own laptop or
desktop without pushing them

268
00:11:52,456 --> 00:11:55,526
to the server or you can
also push them to the server.

269
00:11:55,796 --> 00:11:58,606
This is contrast to things
like SVN which was perhaps,

270
00:11:58,606 --> 00:11:59,986
up until recently, one

271
00:11:59,986 --> 00:12:01,896
of the most popular tools
for version control.

272
00:12:02,066 --> 00:12:03,186
The problem with SVN is

273
00:12:03,186 --> 00:12:05,386
that there's only a
central repository.

274
00:12:05,606 --> 00:12:09,376
If you want to say, I want
to make a check point here

275
00:12:09,376 --> 00:12:11,626
of sorts, and I want to save
this version of my code,

276
00:12:11,806 --> 00:12:14,006
if you're sitting on the train
or you're in your in Starbucks

277
00:12:14,006 --> 00:12:15,916
with no internet access,
you can't do that,

278
00:12:15,966 --> 00:12:17,106
because there's only a server.

279
00:12:17,106 --> 00:12:19,716
So these distributed tools
like, Git, Mercurial, Bazaar,

280
00:12:19,716 --> 00:12:21,666
are definitely the
way to go these days

281
00:12:21,666 --> 00:12:23,366
since you have the
best of both worlds.

282
00:12:23,656 --> 00:12:26,056
So here's a quick review of
commands that will be repeated

283
00:12:26,056 --> 00:12:29,036
in Project Zero's spec and we're
trying to introduce this really

284
00:12:29,036 --> 00:12:30,906
for your own benefit so
that, frankly, in the middle

285
00:12:30,906 --> 00:12:33,086
of the night, when you're
chasing down some bug

286
00:12:33,086 --> 00:12:35,016
or some trying and
implement some new feature,

287
00:12:35,186 --> 00:12:37,296
and you realize, damn that
was a really bad idea,

288
00:12:37,296 --> 00:12:38,766
I just broke my entire code.

289
00:12:38,926 --> 00:12:41,586
All you have to do is run a
command like git-checkout,

290
00:12:41,586 --> 00:12:44,386
and you'll roll back to the
previous version without having

291
00:12:44,386 --> 00:12:46,566
to undo manually all of
the changes you've made.

292
00:12:46,796 --> 00:12:49,946
But the general workflow
is as follows, either some,

293
00:12:49,946 --> 00:12:53,086
a code repository already
exists in the world and you

294
00:12:53,086 --> 00:12:56,046
so to speak clone it and
then you've got a copy of it

295
00:12:56,046 --> 00:12:57,886
and then you can proceed
to do your work there.

296
00:12:58,176 --> 00:12:59,806
For our purposes in the
course, you're not going

297
00:12:59,806 --> 00:13:01,406
to clone an existing repository,

298
00:13:01,406 --> 00:13:02,816
because your project
doesn't exist yet.

299
00:13:03,096 --> 00:13:04,986
Rather, you're going to
create an empty directory

300
00:13:04,986 --> 00:13:06,096
as I'll start to do tonight.

301
00:13:06,336 --> 00:13:08,416
You're going to run a
command like git-init,

302
00:13:08,806 --> 00:13:11,316
which will initialize
that directory as being

303
00:13:11,316 --> 00:13:15,036
for a source code repository,
then you'll type git-add,

304
00:13:15,126 --> 00:13:17,446
which will add files
to that repository.

305
00:13:17,706 --> 00:13:19,266
And then you'll run git-commit,

306
00:13:19,656 --> 00:13:21,836
which saves that
checkpoint so to speak.

307
00:13:21,836 --> 00:13:23,136
And this do this once ourselves.

308
00:13:23,466 --> 00:13:25,656
And then git-push meanwhile
is a little different.

309
00:13:25,656 --> 00:13:28,386
Git-push-- where do you
think it pushes the code to,

310
00:13:29,046 --> 00:13:30,456
if not your local repository?

311
00:13:33,436 --> 00:13:34,456
Yeah. Yep.

312
00:13:34,456 --> 00:13:35,546
Exactly. The server.

313
00:13:35,726 --> 00:13:36,996
So where is the server?

314
00:13:36,996 --> 00:13:38,536
We'll come back to
that in just a moment.

315
00:13:38,706 --> 00:13:40,356
Git-pull is the opposite
of that,

316
00:13:40,356 --> 00:13:42,036
so if you are using
a central server,

317
00:13:42,036 --> 00:13:44,526
you can pull changes
down, which is useful

318
00:13:44,526 --> 00:13:46,436
if you own multiple
computers and you want to work

319
00:13:46,436 --> 00:13:48,236
on this laptop, but then
the next day at work,

320
00:13:48,236 --> 00:13:50,316
you want to work on another
computer but you don't want

321
00:13:50,406 --> 00:13:52,076
to have to put your
code on a USB drive

322
00:13:52,076 --> 00:13:53,096
or something silly like that.

323
00:13:53,456 --> 00:13:55,446
You can just run git-pull
on the second computer

324
00:13:55,446 --> 00:13:57,446
and that will copy down
the changes you pushed

325
00:13:57,546 --> 00:14:00,766
from the first computer and
git-branch refers to this idea

326
00:14:00,766 --> 00:14:03,816
of branching that we discussed
via the picture a moment ago.

327
00:14:04,076 --> 00:14:05,536
So where is this central server?

328
00:14:05,536 --> 00:14:08,566
So we'll encourage you to do
in the spec is to actually sign

329
00:14:08,566 --> 00:14:10,756
up for an account on
this free service.

330
00:14:10,756 --> 00:14:15,206
So bitbucket is a
freely available service

331
00:14:15,346 --> 00:14:17,646
that allows you to
create git-repositories,

332
00:14:17,646 --> 00:14:18,736
both public and private.

333
00:14:19,036 --> 00:14:21,296
Public generally refers to open
source software that you want

334
00:14:21,296 --> 00:14:24,096
to make available to the
world, to the biggest example

335
00:14:24,096 --> 00:14:27,256
of this type of site is githubb,
if you're familiar with them

336
00:14:27,256 --> 00:14:28,436
by name or by practice.

337
00:14:28,756 --> 00:14:30,366
What's nice though
about bitbucket is

338
00:14:30,366 --> 00:14:31,736
that even though
they're not as popular,

339
00:14:31,956 --> 00:14:35,986
they offer unlimited
free, unlimited free

340
00:14:35,986 --> 00:14:38,376
and private repositories
to people associated

341
00:14:38,376 --> 00:14:40,846
with the university,
whereas githubb charges

342
00:14:40,846 --> 00:14:43,776
for private repositories, at
least for a non-trivial number.

343
00:14:43,986 --> 00:14:45,176
So we'll encourage
you to do this

344
00:14:45,266 --> 00:14:48,016
so that you have a central place
to store your code not only

345
00:14:48,016 --> 00:14:50,616
for the semester, but really
for posterity, but particularly

346
00:14:50,616 --> 00:14:52,966
since it'll let keep your
intellectual property private.

347
00:14:53,066 --> 00:14:56,616
But more on that in the, in
the project's specification.

348
00:14:57,086 --> 00:14:59,166
Any questions?

349
00:14:59,166 --> 00:15:06,486
So if I were to ask what
is, what are two upsides

350
00:15:06,486 --> 00:15:07,426
of using source control?

351
00:15:07,746 --> 00:15:09,626
Sort of quiz like; can you
give me one or two of them?

352
00:15:10,166 --> 00:15:10,266
Yeah.

353
00:15:11,526 --> 00:15:13,726
>> If you break something
you can roll back

354
00:15:13,726 --> 00:15:15,796
to something that
you had before.

355
00:15:15,946 --> 00:15:17,446
>> Good. So if you break
something, you can roll back

356
00:15:17,566 --> 00:15:19,046
to a version you had before, or

357
00:15:19,106 --> 00:15:22,016
>> And all renaming is
done automatically for you.

358
00:15:22,116 --> 00:15:24,046
>> Good so all the
renaming are all

359
00:15:24,046 --> 00:15:26,836
of what would be the renamings
of files is done for you sort

360
00:15:26,836 --> 00:15:28,956
of automatically so that
the file names never change,

361
00:15:28,956 --> 00:15:30,386
and how about something
else, even though it's not

362
00:15:30,386 --> 00:15:31,496
as applicable to the course?

363
00:15:31,916 --> 00:15:33,876
>> You can store things
on a, on a server,

364
00:15:33,946 --> 00:15:36,206
so if your laptop breaks, you're
still going to have [inaudible].

365
00:15:36,246 --> 00:15:37,416
>> Oh, so that's another one.

366
00:15:37,416 --> 00:15:39,356
So the ability to push
to a central server means

367
00:15:39,356 --> 00:15:41,246
if your laptop breaks
or you're just elsewhere

368
00:15:41,246 --> 00:15:42,856
on a different computer,
you still have access.

369
00:15:43,366 --> 00:15:43,786
This is good.

370
00:15:43,786 --> 00:15:44,566
We're breaking two.

371
00:15:44,566 --> 00:15:44,666
Yeah.

372
00:15:45,236 --> 00:15:46,726
>> Easy collaboration.

373
00:15:46,726 --> 00:15:48,396
>> Yeah. Easy collaboration,
as well.

374
00:15:48,396 --> 00:15:50,736
So especially after the course
if you dive into some project

375
00:15:50,736 --> 00:15:53,196
and you want to work with a
buddy on it, this is the way

376
00:15:53,196 --> 00:15:54,446
to do it, whether with a public

377
00:15:54,446 --> 00:15:56,696
or private central
repository using a service

378
00:15:56,736 --> 00:16:00,026
like bitbucket, githubb,
or the like.

379
00:16:00,516 --> 00:16:01,526
Alright. So excellent.

380
00:16:01,526 --> 00:16:03,836
More on that in the spec itself.

381
00:16:03,836 --> 00:16:07,186
So this notion of MVC.

382
00:16:07,186 --> 00:16:09,156
How did we get to this point?

383
00:16:09,156 --> 00:16:12,866
Well let me go ahead and pull
up one of last week's examples

384
00:16:12,866 --> 00:16:15,826
where we left off and go to

385
00:16:20,066 --> 00:16:24,646
Lecture two source, which
gave us these examples here.

386
00:16:25,006 --> 00:16:27,796
Oh, so actually, let me take a
step back, since I'm now inside

387
00:16:27,796 --> 00:16:29,346
of the environment
of the appliance.

388
00:16:29,826 --> 00:16:31,846
So the [inaudible]
of the appliance,

389
00:16:31,976 --> 00:16:33,386
again is this virtual machine.

390
00:16:33,386 --> 00:16:35,406
It's an installation of
Linux that you can run

391
00:16:35,406 --> 00:16:37,126
on your own MAC, on your own PC,

392
00:16:37,126 --> 00:16:38,906
or even on your own
Linux computer

393
00:16:38,906 --> 00:16:39,866
if that's what you're running.

394
00:16:40,156 --> 00:16:42,376
And what I simply did
on my MAC is I opened

395
00:16:42,376 --> 00:16:45,726
up a program a moment
ago called VMWare Fusion.

396
00:16:45,726 --> 00:16:49,136
VMWare Fusion is a hyper visor,
and a hyper visor is a program

397
00:16:49,136 --> 00:16:52,356
that lets you play, or that
is run virtual machines

398
00:16:52,406 --> 00:16:53,146
like the appliance.

399
00:16:53,306 --> 00:16:57,546
For the course, we have site
licenses for VMWare Fusion

400
00:16:57,546 --> 00:17:00,096
if you are a MAC user and
they're instruction in this,

401
00:17:00,436 --> 00:17:02,926
on the course's website
on how to access this

402
00:17:02,926 --> 00:17:04,696
when you download
the appliance itself.

403
00:17:04,756 --> 00:17:08,946
For PC users, Windows or Linux,
there exists a free version

404
00:17:08,946 --> 00:17:11,736
of this same tool called VMWare
Player, which will allow you

405
00:17:11,736 --> 00:17:14,446
to run the CS50 appliance and
all sort of other appliances

406
00:17:14,446 --> 00:17:16,216
that people make
available as well.

407
00:17:16,836 --> 00:17:20,436
So I ran Fusion, I imported
the appliance by going to file,

408
00:17:20,616 --> 00:17:23,526
open, essentially, again more on
that in the actual instructions.

409
00:17:23,716 --> 00:17:26,566
And then I double-clicked
it and Linux booted up.

410
00:17:26,566 --> 00:17:28,126
And I simply have
full-screened here

411
00:17:28,126 --> 00:17:29,856
so that we can see
everything within the scope

412
00:17:29,856 --> 00:17:32,196
of just one window and it
looks a little familiar

413
00:17:32,196 --> 00:17:33,746
to windows, or even MAC OS.

414
00:17:33,746 --> 00:17:35,346
We've got a menu
here at the bottom.

415
00:17:35,536 --> 00:17:37,966
We've got some icons to
common programs here,

416
00:17:38,146 --> 00:17:39,666
among which is a
terminal window.

417
00:17:39,916 --> 00:17:41,556
Terminal window, we're going
to start getting acquainted

418
00:17:41,556 --> 00:17:42,806
with all the more,
and this is sort

419
00:17:42,806 --> 00:17:46,066
of your old school style
DOS prompt command prompt

420
00:17:46,066 --> 00:17:48,606
where you can type individual
commands, but this is very much

421
00:17:48,606 --> 00:17:51,546
where you would live and
typically in the web world

422
00:17:51,546 --> 00:17:54,076
when setting up a
server or uploading files

423
00:17:54,076 --> 00:17:55,486
when you don't have,
for instances,

424
00:17:55,486 --> 00:17:58,406
a gooey that some web posting
company provides you with.

425
00:17:58,406 --> 00:18:01,086
And there's also a text editor,
chrome, and more down there.

426
00:18:01,446 --> 00:18:02,386
So let me go ahead and do this.

427
00:18:02,746 --> 00:18:05,156
Let me go ahead and open
up a terminal window

428
00:18:05,156 --> 00:18:07,996
by clicking the little black
icon, and that gives me a window

429
00:18:07,996 --> 00:18:11,046
that looks like this here and
you'll notice that my name

430
00:18:11,226 --> 00:18:14,266
and your name soon is just
John Harvard, and I am logged

431
00:18:14,266 --> 00:18:17,636
into the appliance and in
parenthesis there is a tilde.

432
00:18:18,146 --> 00:18:21,756
And those familiar with Linux,
what does the tilde represent?

433
00:18:23,876 --> 00:18:25,286
Okay. Connor.

434
00:18:25,406 --> 00:18:25,646
Axle.

435
00:18:25,646 --> 00:18:28,046
>> It could be the
home of [inaudible].

436
00:18:28,156 --> 00:18:30,236
>> Exactly, the home
directory so to speak.

437
00:18:30,236 --> 00:18:33,106
So every user on the Linux
computer, and also MAC OS

438
00:18:33,106 --> 00:18:35,256
and Windows these days,
has a home directory

439
00:18:35,376 --> 00:18:37,666
and the home directory is
just where you put your stuff.

440
00:18:37,666 --> 00:18:39,196
On a MAC, it's called
your user name.

441
00:18:39,396 --> 00:18:42,026
On Windows, it's also called
your user name, and it's usually

442
00:18:42,026 --> 00:18:47,616
in slash users on a MAC or
in c:documents and settings

443
00:18:47,616 --> 00:18:50,076
on a Windows computer
and the like, same idea.

444
00:18:50,136 --> 00:18:53,886
So inside of this appliance,
we have our own home directory,

445
00:18:54,046 --> 00:18:57,246
inside of which might be zero
or more files and folders.

446
00:18:57,246 --> 00:19:00,066
So I'm going to go ahead and
type a quick command here

447
00:19:00,466 --> 00:19:02,226
to get us up and
running on the web.

448
00:19:02,436 --> 00:19:03,506
But first, let me do this.

449
00:19:03,506 --> 00:19:05,996
Let me open up chrome
inside of the appliance

450
00:19:06,566 --> 00:19:08,646
and Google comes
up here by default.

451
00:19:08,646 --> 00:19:09,916
But instead I want to go

452
00:19:09,916 --> 00:19:13,166
to http://localhost
just like last week.

453
00:19:13,416 --> 00:19:15,396
And what does localhost
refer to exactly?

454
00:19:15,986 --> 00:19:19,626
What does local host refer to?

455
00:19:19,896 --> 00:19:20,046
Yeah.

456
00:19:20,516 --> 00:19:22,196
>> Whatever is actually
on [inaudible].

457
00:19:22,196 --> 00:19:23,886
>> Exactly, whatever is
actually on the server.

458
00:19:23,886 --> 00:19:26,466
So I'm inside of the appliance
right now, so localhost is

459
00:19:26,466 --> 00:19:29,156
as the name implies, the local
host, the local computer.

460
00:19:29,326 --> 00:19:30,586
And I go ahead and
hit enter here,

461
00:19:30,586 --> 00:19:33,516
and recall that we did this
last time, hello world,

462
00:19:33,706 --> 00:19:35,986
which I tossed into
that default, excuse me,

463
00:19:35,986 --> 00:19:37,916
directory known as VAR.WWW/HTML.

464
00:19:38,066 --> 00:19:42,056
That's simply where many
servers' files go by default,

465
00:19:42,276 --> 00:19:43,736
but this wasn't much
of interest,

466
00:19:43,736 --> 00:19:46,326
it was just an index
dot html page.

467
00:19:46,646 --> 00:19:50,456
So let's instead now navigate
our way to backslash, tilde,

468
00:19:50,456 --> 00:19:53,366
jharvard also like we
last week and hit enter.

469
00:19:53,576 --> 00:19:55,756
But this time, this
week, I've undone a lot

470
00:19:55,756 --> 00:19:58,126
of the changes we made last
week so that we can start fresh

471
00:19:58,126 --> 00:20:00,156
and walk through the process
of getting this set up.

472
00:20:00,706 --> 00:20:01,286
So this is bad.

473
00:20:01,746 --> 00:20:04,946
J. Harvard was backslash
tilde jharvard was not found

474
00:20:04,946 --> 00:20:05,646
on the server.

475
00:20:05,646 --> 00:20:08,256
So John Harvard has no website.

476
00:20:08,776 --> 00:20:11,816
So what directory is
probably missing in this case

477
00:20:11,816 --> 00:20:14,536
that would explain why John
Harvard has not website?

478
00:20:14,636 --> 00:20:14,756
Yeah.

479
00:20:15,266 --> 00:20:16,616
>> Public html.

480
00:20:16,846 --> 00:20:18,856
>> Yeah. So if I do an LS here,

481
00:20:19,086 --> 00:20:21,746
notice that I have a few
directories in my home directory

482
00:20:21,746 --> 00:20:24,046
by default, one of which
I downloaded in advance.

483
00:20:24,046 --> 00:20:25,716
I've got desktop
and downloads just

484
00:20:25,716 --> 00:20:27,216
like a MAC or a PC these days.

485
00:20:27,476 --> 00:20:29,856
Logs, which happen to
refer to web server logs.

486
00:20:29,856 --> 00:20:32,276
And source, which I downloaded
in advance for lectures

487
00:20:32,276 --> 00:20:34,836
and precreated lecture examples.

488
00:20:35,136 --> 00:20:36,926
But I'm obviously
missing public html.

489
00:20:37,266 --> 00:20:38,476
So let's create that.

490
00:20:38,476 --> 00:20:40,186
I can do this in
a couple of ways.

491
00:20:40,186 --> 00:20:45,046
The sort of real technical way
to do it is mkdirpublic_html.

492
00:20:45,286 --> 00:20:48,336
This is just a convention
that many, many,

493
00:20:48,336 --> 00:20:52,346
many apache web servers
for the default directory

494
00:20:52,416 --> 00:20:53,876
for a user's homepage.

495
00:20:53,876 --> 00:20:57,916
You can change this to anything
you want if you edit httpd.conf,

496
00:20:58,206 --> 00:21:00,316
but this is what again
is the typical default.

497
00:21:00,316 --> 00:21:02,676
So we'll play along, and I'm
going to go ahead and hit enter.

498
00:21:03,276 --> 00:21:05,276
Now just to be clear,
let me go ahead

499
00:21:05,276 --> 00:21:07,986
and minimize my terminal
window for just a moment.

500
00:21:08,266 --> 00:21:09,836
If you're more comfortable
in a gooey,

501
00:21:09,836 --> 00:21:11,056
realize I could just do this.

502
00:21:11,056 --> 00:21:13,306
I could double-click on
home and that would open

503
00:21:13,306 --> 00:21:15,066
up a more familiar file browser.

504
00:21:15,266 --> 00:21:18,076
Then I can do something
like file, create folder,

505
00:21:18,206 --> 00:21:21,206
and I could have done something
like this, create folder,

506
00:21:21,206 --> 00:21:23,466
public html, but you
should get comfortable

507
00:21:23,466 --> 00:21:24,176
with the command lines

508
00:21:24,206 --> 00:21:26,016
since ultimately it'll
be much more powerful

509
00:21:26,226 --> 00:21:27,686
and where you sometimes
need to be

510
00:21:27,846 --> 00:21:29,976
on a web server to
configure things.

511
00:21:30,346 --> 00:21:33,556
So now if I type LS for
list, I see public HTML.

512
00:21:33,926 --> 00:21:39,266
So now, how do I open public
HTML or navigate into?

513
00:21:39,776 --> 00:21:42,306
Yeah. [Inaudible] Okay.

514
00:21:42,856 --> 00:21:43,556
Sure, close.

515
00:21:43,556 --> 00:21:44,746
Change directory.

516
00:21:44,816 --> 00:21:49,106
So CD, public HTML, and
you'll be able to type faster

517
00:21:49,106 --> 00:21:51,316
than you think thanks
to keyboard shortcuts.

518
00:21:51,316 --> 00:21:52,366
So if I start typing PUB

519
00:21:52,366 --> 00:21:54,736
and then I get a little
bored typing it out,

520
00:21:54,926 --> 00:21:57,716
you can often hit tab to do
what's called tab completion,

521
00:21:57,866 --> 00:21:59,896
which will just save you
time on a Linux computer.

522
00:22:00,276 --> 00:22:01,616
Then I'm going to
do LS for list.

523
00:22:01,616 --> 00:22:02,916
There's obviously
nothing in there.

524
00:22:03,206 --> 00:22:07,806
So now I'm going to go ahead
and type genieindex.html

525
00:22:07,806 --> 00:22:11,206
and this going to open up a
text editor that can be used

526
00:22:11,206 --> 00:22:13,696
for all sorts of languages,
one of which is html.

527
00:22:13,866 --> 00:22:18,196
And let me go ahead in a tab
that opens here do doc type,

528
00:22:18,196 --> 00:22:22,276
html, html, and notice
it's going to do some tab,

529
00:22:22,976 --> 00:22:24,666
tag completion for me.

530
00:22:25,056 --> 00:22:28,696
Head tag. Let me go ahead
and do a title tag, now,

531
00:22:29,726 --> 00:22:33,276
inside of that, "Hello World."

532
00:22:33,566 --> 00:22:39,516
Now let me go down here and
do a body and Hello World.

533
00:22:40,316 --> 00:22:42,986
Save this, and now let me
go ahead and close this.

534
00:22:44,126 --> 00:22:46,666
And now notice, once I'm
back at my command prompt,

535
00:22:46,666 --> 00:22:49,646
if I do LS, I see index.html.

536
00:22:49,926 --> 00:22:51,636
So let's see what
the result here is.

537
00:22:51,636 --> 00:22:53,206
Now let me go back
to my browser.

538
00:22:53,566 --> 00:22:56,546
Let me go back to the
same URL, tilde jharvard.

539
00:22:56,706 --> 00:23:01,086
Do I need to do this,
woops, this?

540
00:23:01,226 --> 00:23:01,293
>> No.

541
00:23:01,293 --> 00:23:05,506
>> So no, because again, because
of a setting in httpd.conf,

542
00:23:05,696 --> 00:23:08,266
the default is assumed
to be index.html,

543
00:23:08,266 --> 00:23:11,996
or if you're running PHP, it
will also look for index.php,

544
00:23:11,996 --> 00:23:13,656
as well as a couple
other file names.

545
00:23:13,916 --> 00:23:14,736
So now I hit enter.

546
00:23:15,436 --> 00:23:16,936
Damn. I did something wrong.

547
00:23:17,256 --> 00:23:19,486
So first of all, what
is the http status code

548
00:23:19,616 --> 00:23:20,436
in question here?

549
00:23:21,016 --> 00:23:21,106
Yeah.

550
00:23:22,036 --> 00:23:22,466
>> Inaudible.

551
00:23:23,516 --> 00:23:24,106
>> Four oh three.

552
00:23:24,106 --> 00:23:25,916
It's barely visible in
chrome in these days.

553
00:23:25,916 --> 00:23:28,106
But if you look at the
tab up top, you see 403;

554
00:23:28,106 --> 00:23:30,286
403 means forbidden,
which has something to do

555
00:23:30,286 --> 00:23:32,546
with file permission, so
I screwed up somewhere.

556
00:23:32,826 --> 00:23:35,776
So let me go back to my
prompt, and how do I go

557
00:23:35,776 --> 00:23:36,866
about diagnosing this.

558
00:23:36,866 --> 00:23:37,806
Let's not solve it yet.

559
00:23:37,806 --> 00:23:40,216
What did we do last
week to diagnose this.

560
00:23:40,786 --> 00:23:41,076
>> LSAL.

561
00:23:42,456 --> 00:23:45,996
>> Good. LS-AL and this will
show us a couple things.

562
00:23:45,996 --> 00:23:47,766
A, it will show us all files,

563
00:23:47,766 --> 00:23:49,636
including what are
called dot files,

564
00:23:49,746 --> 00:23:51,956
which are simply files who's
name start with a period,

565
00:23:52,186 --> 00:23:54,136
and those are just
generally hidden by default.

566
00:23:54,196 --> 00:23:55,076
There not really hidden,

567
00:23:55,076 --> 00:23:57,276
it's just by default LS
won't show them to you,

568
00:23:57,506 --> 00:23:58,626
so it's a common convention.

569
00:23:58,876 --> 00:24:03,076
And now here we have on a left,
because I did L a long listing.

570
00:24:03,296 --> 00:24:06,466
So besides seeing Index.html
and dot, and dot, dot,

571
00:24:06,666 --> 00:24:08,926
I see the permissions for
each of those directories.

572
00:24:08,926 --> 00:24:12,976
What are the permissions for
index.html right now implying?

573
00:24:13,726 --> 00:24:13,836
Yeah.

574
00:24:14,176 --> 00:24:17,086
>> Only you are allowed to
read and write [inaudible].

575
00:24:17,166 --> 00:24:17,766
>> Exactly.

576
00:24:17,766 --> 00:24:20,596
Only I am allowed to read
and write the file right now

577
00:24:20,596 --> 00:24:24,756
because you only see
an RW on the very left,

578
00:24:25,116 --> 00:24:27,896
and recall that the
left most R and W in X

579
00:24:28,226 --> 00:24:29,946
if present refer to the owner.

580
00:24:30,356 --> 00:24:33,986
The next triple, R or W
or X, refers to the group,

581
00:24:34,146 --> 00:24:35,706
which in my case is
going to be students

582
00:24:35,706 --> 00:24:37,526
because John Harvard's
supposed to be a student.

583
00:24:37,526 --> 00:24:40,666
And then the last
three refer to whom.

584
00:24:41,466 --> 00:24:41,646
>> Other.

585
00:24:42,056 --> 00:24:43,826
>> Other. So everyone
else in the world,

586
00:24:43,826 --> 00:24:46,506
which is pretty relevant
in the world of the web

587
00:24:46,766 --> 00:24:48,966
because you're obviously
trying to get other people

588
00:24:48,966 --> 00:24:50,926
on the internet, in
this case, even yourself

589
00:24:50,926 --> 00:24:52,726
on a browser to view
those files.

590
00:24:53,016 --> 00:24:54,306
So we need to give more

591
00:24:54,306 --> 00:24:56,426
than just me readability
to this file.

592
00:24:56,426 --> 00:24:58,216
Not write-ability,
but readability.

593
00:24:58,216 --> 00:24:59,856
So does anyone recall
the command

594
00:24:59,856 --> 00:25:03,286
for doing this last time?

595
00:25:03,526 --> 00:25:03,736
Yeah.

596
00:25:05,416 --> 00:25:05,576
>> Chmod [inaudible].

597
00:25:05,736 --> 00:25:09,476
>> Good. Chmod for change
mode, A plus R for file name,

598
00:25:09,836 --> 00:25:12,176
followed by the file
name, enter,

599
00:25:12,416 --> 00:25:15,786
LS-L now shows me indeed an R

600
00:25:15,786 --> 00:25:17,696
for everyone, including
my group.

601
00:25:17,696 --> 00:25:19,106
My group's not really
that relevant,

602
00:25:19,106 --> 00:25:21,076
but my group is a subset
of the whole world,

603
00:25:21,376 --> 00:25:23,116
so that's fine, as well.

604
00:25:23,376 --> 00:25:25,016
Now, because you'll
see it online,

605
00:25:25,016 --> 00:25:26,796
let's do this slightly
more technically.

606
00:25:26,796 --> 00:25:31,806
Let me undo that and say A
minus R and now do dash L,

607
00:25:31,806 --> 00:25:33,356
and now actually, now
I really screwed up.

608
00:25:33,356 --> 00:25:34,836
Now even I can't view it.

609
00:25:34,836 --> 00:25:38,576
So Chmod U plus R
for index.html,

610
00:25:38,576 --> 00:25:40,936
and now I have my
readability back.

611
00:25:40,936 --> 00:25:41,796
U for user.

612
00:25:42,076 --> 00:25:43,906
So let's do this a
little more technically

613
00:25:43,906 --> 00:25:44,976
so that you've seen it before.

614
00:25:44,976 --> 00:25:47,826
I'm going to go ahead and open
up a little scratch pad here,

615
00:25:47,826 --> 00:25:52,566
text edit, just so we
have a place to see this

616
00:25:53,626 --> 00:25:54,936
and let me go ahead and do this.

617
00:25:56,176 --> 00:26:00,156
So we just did A plus
R, and I also did,

618
00:26:00,666 --> 00:26:04,546
just now U plus R, and so forth.

619
00:26:04,546 --> 00:26:05,606
This is a nice convention.

620
00:26:05,836 --> 00:26:08,486
But it would seem to allow
you to toggle just read

621
00:26:08,486 --> 00:26:11,286
or writeability on a
given group, yourself,

622
00:26:11,366 --> 00:26:13,176
your actual group, or the world.

623
00:26:13,406 --> 00:26:15,456
We can actually be a
little more powerful here.

624
00:26:15,456 --> 00:26:21,696
So let me actually go back to
a listing that looks like this.

625
00:26:21,896 --> 00:26:21,986
DRW-- - - - - - .

626
00:26:21,986 --> 00:26:26,856
So, the D denotes
what, typically?

627
00:26:26,856 --> 00:26:27,466
Directory.

628
00:26:28,136 --> 00:26:34,586
So I'm going to get rid of
that now that we've seen

629
00:26:34,726 --> 00:26:35,916
because we're talking
about a file.

630
00:26:36,136 --> 00:26:38,466
So this is what we saw a moment
ago when we got forbidden.

631
00:26:38,586 --> 00:26:42,856
Now the first three hyphens
that follow are for the owner,

632
00:26:43,166 --> 00:26:46,456
the next three are group, and
the last three are everyone.

633
00:26:46,686 --> 00:26:48,706
Alright, so that's just a
recap of where we started.

634
00:26:49,036 --> 00:26:51,986
But it turns out that I could
have accomplished the same thing

635
00:26:51,986 --> 00:26:58,526
with Chmod 644 index.html; 644.

636
00:26:58,526 --> 00:26:59,906
Well where does it come from?

637
00:26:59,906 --> 00:27:02,326
Well, turns out that there's
a little cheat sheet here.

638
00:27:02,326 --> 00:27:06,866
Four typically denotes
R, 2 denotes right,

639
00:27:06,866 --> 00:27:11,726
and 1 denotes X,
for executability.

640
00:27:11,986 --> 00:27:15,986
So these are what are
actually called octal numbers

641
00:27:15,986 --> 00:27:17,196
for the following reason.

642
00:27:17,196 --> 00:27:20,186
If you add these
things up four and 2,

643
00:27:20,186 --> 00:27:20,996
obviously what do you get?

644
00:27:21,466 --> 00:27:22,396
Nothing technical about this.

645
00:27:22,926 --> 00:27:23,666
You get 6.

646
00:27:24,116 --> 00:27:27,706
So why does 644 represent
the exact same string

647
00:27:27,706 --> 00:27:30,806
that we created earlier with
the shortcuts, like A plus R

648
00:27:30,806 --> 00:27:32,086
and U plus R and the like.

649
00:27:32,426 --> 00:27:39,516
Well, 644 refers to first; this
6 maps to these three hyphens,

650
00:27:39,976 --> 00:27:44,726
this 4 maps to the next three
hyphens, and the last 4 maps

651
00:27:44,726 --> 00:27:49,046
to the last three hyphens,
and so 4 means readability

652
00:27:49,046 --> 00:27:51,066
for everyone, 4 means
readability for my group,

653
00:27:51,066 --> 00:27:53,916
and 6 means readability
and writeability for me.

654
00:27:54,076 --> 00:27:54,726
And it's octal [inaudible]

655
00:27:54,726 --> 00:27:57,096
because you can count
up as high as 7.

656
00:27:57,336 --> 00:28:00,366
If you add all of these number
together, 4 plus 2 plus 1,

657
00:28:00,516 --> 00:28:02,866
and the lowest number you
can count from is zero,

658
00:28:03,126 --> 00:28:06,256
so we essentially have
a range of zero to 8,

659
00:28:06,476 --> 00:28:09,186
a range of 8 total values.

660
00:28:09,596 --> 00:28:13,566
Okay. And actually, you
want a really geeky aside?

661
00:28:13,886 --> 00:28:14,866
Why does this actually work?

662
00:28:14,866 --> 00:28:17,306
These hyphens are actually
placeholders for bits.

663
00:28:17,956 --> 00:28:21,386
So in fact if you want to
give someone writeability,

664
00:28:21,706 --> 00:28:25,706
the whole world rather,
readability, you would do this.

665
00:28:25,896 --> 00:28:26,876
You would set that to 1.

666
00:28:26,976 --> 00:28:29,246
If you want to also let the
whole world write your file,

667
00:28:29,496 --> 00:28:31,756
you would do this, and
then you would leave this.

668
00:28:31,786 --> 00:28:34,056
Rather, let's say you just want

669
00:28:34,056 --> 00:28:35,556
to give the whole
world readability.

670
00:28:35,726 --> 00:28:37,356
Well what's this
number in binary,

671
00:28:37,496 --> 00:28:38,566
if you convert it to decimal?

672
00:28:45,076 --> 00:28:45,476
Four. Right?

673
00:28:45,536 --> 00:28:47,736
So this is the one's place,
this is the two's place,

674
00:28:47,736 --> 00:28:49,536
this is the four's
place, if you know binary.

675
00:28:49,796 --> 00:28:52,666
So this represents 4, which is
why readability is represented

676
00:28:52,666 --> 00:28:54,526
by 4, writeability
is represented by 2,

677
00:28:54,526 --> 00:28:56,096
and executability
is represented by 1.

678
00:28:56,386 --> 00:28:58,056
Okay, random technical
aside that you need,

679
00:28:58,056 --> 00:28:59,546
don't need to understand
at a low level,

680
00:28:59,766 --> 00:29:01,176
but hopefully now just
with these numbers,

681
00:29:01,176 --> 00:29:02,746
you can express any
set of permissions

682
00:29:02,816 --> 00:29:03,866
that you actually want to.

683
00:29:04,106 --> 00:29:06,416
So let's actually summarize
with a quick cheat sheet now.

684
00:29:06,676 --> 00:29:11,346
So for my, for my html
file, I wanted 644.

685
00:29:11,346 --> 00:29:13,356
However, 604 would work as well,

686
00:29:13,356 --> 00:29:15,756
but generally just keeping
the last two the same is fine.

687
00:29:16,156 --> 00:29:20,016
What other types of files would
you probably want to be 644.

688
00:29:20,016 --> 00:29:22,966
In other words, world readable,
but also writeable by you?

689
00:29:23,506 --> 00:29:25,966
What kinds of files in
the context of the web?

690
00:29:32,106 --> 00:29:34,866
Surely there's something else.

691
00:29:34,866 --> 00:29:35,796
Yeah. [Inaudible]
PHP, so good thought,

692
00:29:36,006 --> 00:29:41,316
but we actually don't need our
PHP files to be world readable

693
00:29:41,556 --> 00:29:44,476
because only the web
server needs to be able

694
00:29:44,476 --> 00:29:46,566
to read our PHP files in
order to interpret them,

695
00:29:46,736 --> 00:29:50,276
after which it will spit
out world readable html.

696
00:29:50,606 --> 00:29:51,796
So in fact for security,

697
00:29:51,796 --> 00:29:53,586
and recall our discussion
a couple weeks ago

698
00:29:53,586 --> 00:29:56,696
about SU PHP, substitute
user PHP.

699
00:29:56,696 --> 00:29:59,686
In the interest of security,
PHP files should really be

700
00:29:59,686 --> 00:30:02,516
on a well-designed system, 600,

701
00:30:02,516 --> 00:30:04,886
so that only you can
read and write them.

702
00:30:05,006 --> 00:30:07,786
But that's fine, because recall
that a, a piece of software

703
00:30:07,786 --> 00:30:13,846
like SU PHP, runs as you, so the
implication is that 600 is fine.

704
00:30:14,406 --> 00:30:18,186
So by contrast, what kinds
of files also need to be 644?

705
00:30:20,866 --> 00:30:20,966
Yeah.

706
00:30:21,516 --> 00:30:26,836
[ Inaudible ]

707
00:30:27,336 --> 00:30:31,136
>> Good. So all the other
stuff, so 644 for this, CSS,

708
00:30:31,136 --> 00:30:36,926
644 for this, java script
file, 644 for this, ping,

709
00:30:36,926 --> 00:30:40,526
644 for this, what
about a directory?

710
00:30:41,126 --> 00:30:43,966
What should a directory be?

711
00:30:49,366 --> 00:30:49,466
Yeah.

712
00:30:50,016 --> 00:30:51,476
[ Inaudible ]

713
00:30:51,476 --> 00:30:52,426
>> Okay. So good thought.

714
00:30:52,426 --> 00:30:54,966
So readable by the world but
not writeable, so something

715
00:30:54,966 --> 00:30:57,026
like 644, so readable.

716
00:30:57,356 --> 00:30:59,276
So it turns out this
doesn't work for a directory.

717
00:30:59,386 --> 00:31:00,966
So directories are sort

718
00:31:00,966 --> 00:31:03,276
of conceptually different
from files certainly.

719
00:31:03,786 --> 00:31:08,366
And with directories, in order
to do something with them,

720
00:31:08,516 --> 00:31:09,806
there's two permissions
involved.

721
00:31:09,886 --> 00:31:11,226
One is readability.

722
00:31:11,226 --> 00:31:12,596
Can you see what's inside of it?

723
00:31:12,596 --> 00:31:13,866
So that's reasonable to want.

724
00:31:14,196 --> 00:31:15,806
But the other is executability.

725
00:31:15,806 --> 00:31:17,726
Can you even physically open it

726
00:31:17,726 --> 00:31:20,126
by double-clicking
on it, by typing CD.

727
00:31:20,316 --> 00:31:22,756
So it turns out that
executability in the context

728
00:31:22,756 --> 00:31:25,106
of directories is
necessary if you want

729
00:31:25,106 --> 00:31:27,126
to let the world
into that directory.

730
00:31:27,436 --> 00:31:29,656
So I would actually
refine our definition here

731
00:31:29,656 --> 00:31:32,386
and besides just giving
everyone executability,

732
00:31:32,636 --> 00:31:35,436
which we might be tempted to
do by just adding 1 to each

733
00:31:35,436 --> 00:31:38,536
of these numbers, because recall
that 1 represents executability.

734
00:31:38,786 --> 00:31:41,106
I'm going to propose that you
know what, the world needs

735
00:31:41,106 --> 00:31:45,346
to be able to get into a
directory, like a subdirectory

736
00:31:45,606 --> 00:31:48,266
in my web server, but they don't
need to be able to poke around

737
00:31:48,266 --> 00:31:49,586
and see all of the files.

738
00:31:49,826 --> 00:31:53,046
If they know the name of the
file, and it's readable, fine.

739
00:31:53,316 --> 00:31:55,526
But I don't want to give them
what's called the directory

740
00:31:55,526 --> 00:31:59,016
listing, which shows them all
of the files in a given folder,

741
00:31:59,016 --> 00:32:03,466
and for that would do 755 to
not do that you would do 711.

742
00:32:03,916 --> 00:32:05,166
So in general, this cheat sheet

743
00:32:05,166 --> 00:32:07,956
that we just made
here is pretty,

744
00:32:08,106 --> 00:32:12,006
this is a pretty exhaustive list
of the relevant file formats

745
00:32:12,006 --> 00:32:14,246
that we'll be using for
something like Project Zero

746
00:32:14,246 --> 00:32:17,516
or One or Two, and as
well as for directories.

747
00:32:17,516 --> 00:32:21,646
There's exceptions, but this
is a pretty good rule of thumb.

748
00:32:22,606 --> 00:32:29,786
Alright. So back then to where
we left off here with MVC.

749
00:32:30,046 --> 00:32:33,896
So last time; let me go
ahead and unzip some files

750
00:32:33,896 --> 00:32:34,966
that I just downloaded.

751
00:32:38,056 --> 00:32:43,576
So last time recall, we
had these directories.

752
00:32:44,296 --> 00:32:46,736
We had [inaudible] examples,
we had some login examples,

753
00:32:46,736 --> 00:32:49,606
and we had MVC, and recall
where we started with MVC.

754
00:32:49,606 --> 00:32:54,756
Let me go ahead and open up
index.php for MVC version zero,

755
00:32:55,216 --> 00:32:58,326
and notice that this was simple,

756
00:32:58,726 --> 00:33:01,006
but there's no programming
logic whatsoever.

757
00:33:01,006 --> 00:33:03,846
Even though this is called
index.php, there's no PHP code

758
00:33:03,846 --> 00:33:06,976
in it, and that's fine,
but it's just raw HTML.

759
00:33:07,266 --> 00:33:08,806
But recall that this website;

760
00:33:09,366 --> 00:33:10,836
let me go ahead and
pull this up.

761
00:33:11,556 --> 00:33:14,096
Let me go into jharvard.

762
00:33:14,096 --> 00:33:15,106
And here's the difference.

763
00:33:15,366 --> 00:33:17,886
So now we're in lecture and
frankly I'd kind of like be able

764
00:33:17,886 --> 00:33:19,896
to browse the directory
so I don't have to guess

765
00:33:19,896 --> 00:33:22,486
or remember the names of all
of the files we've created.

766
00:33:22,726 --> 00:33:26,666
So let me go back here to
my public HTML directory

767
00:33:27,086 --> 00:33:32,266
and do LSL-L here and let
me make public HTML 755,

768
00:33:32,606 --> 00:33:35,446
because when I do that, now
watch when I reload-- whoops.

769
00:33:36,226 --> 00:33:38,046
Now I'm getting an
error with index.html.

770
00:33:38,186 --> 00:33:41,396
Let's actually get rid of
index.html and reload this.

771
00:33:41,896 --> 00:33:43,186
Now I get the directory listing.

772
00:33:43,186 --> 00:33:44,776
That's 755.

773
00:33:44,776 --> 00:33:46,046
What we saw a moment
ago was not.

774
00:33:46,046 --> 00:33:48,446
That was 711, or 700.

775
00:33:48,796 --> 00:33:52,026
So now I'm in MVC, now I'm
in version zero, and voila.

776
00:33:52,026 --> 00:33:54,446
This was the incredibly
underwhelming website we started

777
00:33:54,446 --> 00:33:56,596
with last week using just HTML.

778
00:33:56,596 --> 00:33:57,676
But what was the problem.

779
00:33:57,786 --> 00:34:00,136
Well if I click on
lectures, this leads me

780
00:34:00,136 --> 00:34:05,356
to a file called lectures.php
and if I look at that file

781
00:34:05,356 --> 00:34:07,516
at a prompt-- let me
go ahead and do that.

782
00:34:07,516 --> 00:34:12,186
MVC zero and let me go ahead
and open up lectures.php.

783
00:34:12,186 --> 00:34:17,066
Notice that this file looks
awfully familiar, right.

784
00:34:17,066 --> 00:34:18,826
It's a little small,
so let me zoom in.

785
00:34:19,636 --> 00:34:22,676
There's no PHP content
in here either.

786
00:34:22,676 --> 00:34:24,176
It's pretty much
a copy and paste,

787
00:34:24,176 --> 00:34:27,246
but I changed what the menu was,
then when you click on lectures

788
00:34:27,246 --> 00:34:28,796
and get to lecture
zero and lecture 1,

789
00:34:29,066 --> 00:34:30,306
well what did those
files look like?

790
00:34:30,536 --> 00:34:31,506
Pretty much identical.

791
00:34:31,506 --> 00:34:33,416
In other words, we
started with a very clean,

792
00:34:33,416 --> 00:34:36,056
a very simple cite, but a
huge amount of copy paste.

793
00:34:36,056 --> 00:34:38,166
And what's the downside
of this approach,

794
00:34:38,166 --> 00:34:39,726
of just doing each
page from scratch?

795
00:34:40,626 --> 00:34:42,886
Let's pick on this
design a little bit.

796
00:34:43,766 --> 00:34:48,096
Yeah. Conner.

797
00:34:48,096 --> 00:34:51,346
>> I mean if you want to
change the whole site,

798
00:34:51,346 --> 00:34:54,356
it's going to require you to
modify each individual page.

799
00:34:54,356 --> 00:34:54,786
>> Exactly.

800
00:34:54,786 --> 00:34:57,626
If you want to modify the
site, even some silly aesthetic

801
00:34:57,626 --> 00:35:01,066
like the title or the color or
something like, you have to go

802
00:35:01,066 --> 00:35:02,656
through and edit
every file, which, eh,

803
00:35:02,656 --> 00:35:05,306
it's not a big deal
as of last week.

804
00:35:05,376 --> 00:35:06,796
There were four files.

805
00:35:06,796 --> 00:35:12,876
But, what it once, what about
when lecture 2 comes out

806
00:35:12,876 --> 00:35:15,856
and lecture 3 and lecture
4 and 5 and 6 and 7,

807
00:35:15,856 --> 00:35:19,956
now we have a whole lot of files
that we actually have to edit.

808
00:35:19,956 --> 00:35:21,866
What else is bad about this?

809
00:35:21,866 --> 00:35:22,046
Yeah.

810
00:35:22,046 --> 00:35:25,416
>> Well it takes
a long time to do

811
00:35:25,416 --> 00:35:26,776
and it takes up a lot of space.

812
00:35:26,896 --> 00:35:28,996
>> Yeah. It just takes up
more space, and even though,

813
00:35:29,126 --> 00:35:31,206
you know, discs are
cheap these days,

814
00:35:31,296 --> 00:35:36,596
this is just wasting space
really, for no good reason.

815
00:35:36,846 --> 00:35:40,116
It takes more time arguably.

816
00:35:40,286 --> 00:35:43,726
You minimally have to copy
and paste the previous code,

817
00:35:43,726 --> 00:35:46,796
or rewrite it from scratch.

818
00:35:46,796 --> 00:35:52,396
And yet the only content that's
been changing really has been

819
00:35:54,236 --> 00:35:58,506
the menu here, the unordered
list, and the title of the page.

820
00:35:58,506 --> 00:36:01,606
Everything else in this
example thus far has been

821
00:36:01,606 --> 00:36:03,356
structurally identical.

822
00:36:03,356 --> 00:36:05,126
So we can do better than this,

823
00:36:05,216 --> 00:36:09,306
and so we progressively
built up from this.

824
00:36:09,306 --> 00:36:11,916
So let's do a quick recap here.

825
00:36:11,916 --> 00:36:14,866
Let me go into version
1 and recall

826
00:36:14,866 --> 00:36:18,416
that version 1 did
something a little different

827
00:36:18,416 --> 00:36:20,926
and we don't need to
look at the actual code

828
00:36:20,926 --> 00:36:23,586
if you recall this quick
summary in the read me.

829
00:36:23,656 --> 00:36:25,756
What did we introduce
here in terms

830
00:36:25,756 --> 00:36:27,836
of the files that
was compelling?

831
00:36:27,836 --> 00:36:28,726
We had this, yeah.

832
00:36:29,126 --> 00:36:31,536
>> You stored the
header and the footer.

833
00:36:31,686 --> 00:36:32,566
>> Yeah. So we factored out,

834
00:36:32,566 --> 00:36:35,526
we factored out the
header and the footer.

835
00:36:35,526 --> 00:36:41,476
The HTML tag, the title tag,
the head tag, and all of that.

836
00:36:41,546 --> 00:36:46,046
We factored out the close
body tag, close HTML tag

837
00:36:49,556 --> 00:36:53,206
so at least then we were
only requiring at the top

838
00:36:53,206 --> 00:36:54,306
of the file the new content.

839
00:36:54,306 --> 00:36:55,976
So let me do that.

840
00:36:55,976 --> 00:37:00,976
Let me open up index.html
now and let me just do this

841
00:37:01,146 --> 00:37:04,456
at a command line
just for time's sake,

842
00:37:04,456 --> 00:37:06,496
and now this was index.html.

843
00:37:06,616 --> 00:37:09,876
No redundancy whatsoever.

844
00:37:09,946 --> 00:37:12,286
This is all fresh content

845
00:37:12,976 --> 00:37:24,306
and we've additionally required
header.php and footer.php.

846
00:37:24,306 --> 00:37:25,766
And similarly, do all

847
00:37:25,766 --> 00:37:29,846
of the other PHP files
include those particular header

848
00:37:29,846 --> 00:37:33,856
and footers that I
want the user to visit.

849
00:37:33,856 --> 00:37:34,556
So this was better.

850
00:37:35,056 --> 00:37:36,736
But what was not
perfect about this?

851
00:37:36,736 --> 00:37:40,726
Version 2 got even better, 3 got
even better, 4 even got better.

852
00:37:40,806 --> 00:37:41,916
We went through a few of them.

853
00:37:41,916 --> 00:37:44,286
So what were some of the
faults of this earlier design?

854
00:37:44,286 --> 00:37:44,756
>> You can choose say

855
00:37:45,286 --> 00:37:49,606
that something had
headers like the title.

856
00:37:49,606 --> 00:37:50,216
>> Exactly.

857
00:37:50,216 --> 00:37:53,116
Right now, if I'm requiring
header.php; whatever's in there,

858
00:37:53,116 --> 00:37:54,876
is what's going to get spit out.

859
00:37:54,876 --> 00:37:58,246
So I've presumably hardcoded
one title for the whole site.

860
00:37:58,246 --> 00:37:59,906
There's not dynamism, at least

861
00:37:59,906 --> 00:38:02,006
to the stuff that
I factored out.

862
00:38:02,006 --> 00:38:03,426
So that's kind of
a step backwards.

863
00:38:03,426 --> 00:38:06,666
I've paid a price for this
dynamism by losing the ability

864
00:38:06,736 --> 00:38:08,806
to at least customize the title.

865
00:38:08,806 --> 00:38:09,456
So that seems a step backward.

866
00:38:09,486 --> 00:38:10,446
But how did we fix
it last Monday?

867
00:38:10,476 --> 00:38:11,496
How did I give myself
back the ability

868
00:38:11,526 --> 00:38:12,426
to control the title
dynamically?

869
00:38:12,456 --> 00:38:12,966
>> You used a function.

870
00:38:12,996 --> 00:38:13,776
>> Yeah. I used a
function, instead.

871
00:38:13,806 --> 00:38:15,306
So instead of using require,
which is a built-in function

872
00:38:15,336 --> 00:38:16,776
in PHP that does exactly
that, it includes or requires

873
00:38:16,806 --> 00:38:17,496
that file right then and there.

874
00:38:17,526 --> 00:38:18,786
I instead wrote my own
function called render header

875
00:38:18,816 --> 00:38:20,226
and render footer that also
took in addition to the name

876
00:38:20,256 --> 00:38:21,456
of the file I wanted to
render, header or footer,

877
00:38:21,486 --> 00:38:22,506
it also let me pass
in what data type?

878
00:38:22,536 --> 00:38:22,776
>> Variable.

879
00:38:22,806 --> 00:38:23,826
>> A variable, but
what type of variable?

880
00:38:23,856 --> 00:38:24,006
>> An array.

881
00:38:24,036 --> 00:38:24,186
>> An array.

882
00:38:24,216 --> 00:38:25,686
Exactly. And it was an array,
an associate of array at that--

883
00:38:25,716 --> 00:38:26,316
and let me go in here.

884
00:38:26,346 --> 00:38:27,336
If I open up now
version 2's example.

885
00:38:27,366 --> 00:38:28,416
Whoops. Yeah, this is
it-- version 2's example,

886
00:38:28,446 --> 00:38:29,736
it takes an array as its
argument and specifies

887
00:38:29,766 --> 00:38:30,906
that the title key should
have a value of this

888
00:38:30,936 --> 00:38:32,256
so that now I have the
ability to change the values

889
00:38:32,286 --> 00:38:33,636
of variables inside of that
header because if I look

890
00:38:33,666 --> 00:38:35,166
at the render header function--
let me go ahead and do this.

891
00:38:35,196 --> 00:38:36,696
Let me go ahead and open up
helpers.php, which is the file

892
00:38:36,726 --> 00:38:37,326
in which these are defined.

893
00:38:37,356 --> 00:38:38,226
Notice that they
work fairly simply.

894
00:38:38,256 --> 00:38:39,786
They take an argument called
data is the parameter name here.

895
00:38:39,816 --> 00:38:41,136
It then extracts data and
then requires the file.

896
00:38:41,166 --> 00:38:42,336
So the only one that
should be obvious right now,

897
00:38:42,366 --> 00:38:43,596
is this last line,
require.php requires header.php.

898
00:38:43,626 --> 00:38:44,376
What did the previous line do?

899
00:38:44,406 --> 00:38:44,976
What does extract do?

900
00:38:52,106 --> 00:38:53,256
What did extract do?

901
00:38:53,836 --> 00:38:53,916
Yeah.

902
00:38:55,156 --> 00:39:03,996
>> It actually takes the key
value pairs out of the array

903
00:39:03,996 --> 00:39:07,566
and makes them into
variables that you can use.

904
00:39:07,566 --> 00:39:08,126
>> Exactly.

905
00:39:08,186 --> 00:39:10,806
It takes the keys value pairs
out of the array that was passed

906
00:39:10,806 --> 00:39:12,566
in and just makes them
actual local variables.

907
00:39:12,726 --> 00:39:15,506
So if you had a key
of title, you now get,

908
00:39:15,506 --> 00:39:17,656
after calling extract
dollar sign title

909
00:39:17,656 --> 00:39:19,146
as an actual variable.

910
00:39:19,846 --> 00:39:21,316
No why? Who cares?

911
00:39:21,396 --> 00:39:24,666
Well if I look at my header.php
file, notice that it looks

912
00:39:24,666 --> 00:39:28,586
like this up, this is nice
and simple with the title.

913
00:39:28,676 --> 00:39:30,106
Now if I didn't do extract,

914
00:39:30,106 --> 00:39:31,546
that's not a key
ingredient here.

915
00:39:31,546 --> 00:39:34,346
I can still access things, but
instead I would have to do this,

916
00:39:34,906 --> 00:39:36,506
data "title" in square
brackets to get that key back.

917
00:39:36,536 --> 00:39:37,976
So why do you think I called
extract in the first place?

918
00:39:43,106 --> 00:39:44,436
Why bother calling extract?

919
00:39:56,046 --> 00:39:57,196
If you had to guess.

920
00:39:57,256 --> 00:39:57,966
I'll take guesses.

921
00:40:01,066 --> 00:40:02,566
Okay, if you think
you know; oh, yeah.

922
00:40:03,016 --> 00:40:04,166
[ Inaudible ]

923
00:40:04,166 --> 00:40:04,666
>> Yeah. Good.

924
00:40:04,866 --> 00:40:05,616
Okay. One point.

925
00:40:05,886 --> 00:40:06,776
Yeah. Very honestly.

926
00:40:06,776 --> 00:40:07,856
It's the simplicity of it.

927
00:40:07,856 --> 00:40:10,186
So one, I just didn't want
to type dollar sign, data,

928
00:40:10,186 --> 00:40:11,736
quote unquote, all
over the place,

929
00:40:11,926 --> 00:40:13,336
because it's just not necessary,

930
00:40:13,336 --> 00:40:15,206
especially if I've created
these local variables

931
00:40:15,206 --> 00:40:17,276
within the function,
it should be sufficient

932
00:40:17,276 --> 00:40:18,266
to just type their name.

933
00:40:18,356 --> 00:40:18,456
Yeah.

934
00:40:19,516 --> 00:40:22,596
[ Inaudible ]

935
00:40:23,096 --> 00:40:25,646
In this case, I've just
defined one key value pair,

936
00:40:25,646 --> 00:40:28,286
so it's a little silly to
bother indexing into an array.

937
00:40:28,636 --> 00:40:30,586
But even then, if I had
more key value pairs,

938
00:40:30,586 --> 00:40:33,026
it really is just the
simplicity again that appeals.

939
00:40:33,176 --> 00:40:34,136
And what was your name, again?

940
00:40:34,646 --> 00:40:34,926
>> Me?

941
00:40:34,926 --> 00:40:35,046
>> Yeah.

942
00:40:35,176 --> 00:40:35,826
>> Isaac.

943
00:40:35,826 --> 00:40:36,386
>> Isaac. That's right.

944
00:40:36,556 --> 00:40:37,066
Sorry, I forgot.

945
00:40:37,146 --> 00:40:37,246
Yeah.

946
00:40:37,686 --> 00:40:41,466
>> Also, if you ever change the
data, you'll have to go through

947
00:40:41,576 --> 00:40:42,456
and change all of these arrays.

948
00:40:42,606 --> 00:40:43,826
>> Yeah. So, that's
a fair point.

949
00:40:43,826 --> 00:40:45,836
If for what, maybe it's
more of corner case,

950
00:40:45,836 --> 00:40:47,736
but if you ever change the
name of that local variable,

951
00:40:47,736 --> 00:40:49,916
now you have to change
it everywhere, as well.

952
00:40:49,986 --> 00:40:51,006
Sure, that's reasonable.

953
00:40:51,226 --> 00:40:52,886
So just a little bit cleaner

954
00:40:53,236 --> 00:40:56,756
but let's resolve one other open
question here, if we go back

955
00:40:56,756 --> 00:40:59,726
to the render header
function, what is the deal

956
00:40:59,726 --> 00:41:03,546
with the equal sign and the
empty array function call?

957
00:41:04,226 --> 00:41:04,976
What's that doing for me?

958
00:41:09,176 --> 00:41:09,296
Yeah.

959
00:41:09,906 --> 00:41:11,166
>> Just creating an array.

960
00:41:11,166 --> 00:41:13,416
>> Just creating an array when?

961
00:41:14,356 --> 00:41:14,476
>> When?

962
00:41:14,666 --> 00:41:16,156
>> Or under what circumstances?

963
00:41:16,736 --> 00:41:16,866
Isaac?

964
00:41:17,576 --> 00:41:18,766
>> Taking an argument.

965
00:41:19,906 --> 00:41:22,496
>> It is taking an argument,
and that argument's called data,

966
00:41:22,496 --> 00:41:24,496
but if I'm passing in an array,

967
00:41:24,496 --> 00:41:26,386
why am I saying equal
sign array?

968
00:41:26,626 --> 00:41:26,746
Yeah.

969
00:41:31,576 --> 00:41:34,276
>> It defines that if data
doesn't having anything,

970
00:41:34,276 --> 00:41:37,516
it creates an array that's
completely empty inputs

971
00:41:37,516 --> 00:41:38,176
for data.

972
00:41:38,176 --> 00:41:43,206
>> Exactly, if I call render
header without any arguments,

973
00:41:43,206 --> 00:41:46,206
which I might if I just don't
need to pass in any arguments.

974
00:41:46,206 --> 00:41:47,856
And in fact that happens
with render footer.

975
00:41:47,856 --> 00:41:50,656
I at least want dollar sign
data to be of type array so that

976
00:41:50,656 --> 00:41:53,746
when I call extract,
extract doesn't freak

977
00:41:53,746 --> 00:41:55,806
out because I've passed
it some null value.

978
00:41:55,806 --> 00:41:59,056
Extract expects an
array, so this is just a,

979
00:41:59,056 --> 00:42:01,586
a one-line clever way of
ensuring that I'm passing

980
00:42:01,586 --> 00:42:04,096
in an array, because otherwise I
would have to do something like,

981
00:42:04,096 --> 00:42:07,516
if is array data, then
call extract, and you know,

982
00:42:07,516 --> 00:42:09,666
it's fine, totally
correct and reasonable.

983
00:42:09,926 --> 00:42:12,666
But I can do it a little
more elegantly by ensuring

984
00:42:12,666 --> 00:42:15,086
that data itself
has a default value.

985
00:42:15,086 --> 00:42:19,316
So, the equal sign just
implies a default value there.

986
00:42:19,506 --> 00:42:22,606
Alright, any questions on those?

987
00:42:22,816 --> 00:42:23,436
No. Alright.

988
00:42:23,436 --> 00:42:26,116
So how much further did we go?

989
00:42:26,116 --> 00:42:27,236
Well in version three,

990
00:42:27,236 --> 00:42:29,026
we did something a
little bit different,

991
00:42:29,346 --> 00:42:32,256
but now I still have
footer.html,

992
00:42:32,256 --> 00:42:36,276
I still have header.html,
sorry, footer.php, header.php,

993
00:42:36,276 --> 00:42:37,796
I still have helpers.php.

994
00:42:37,796 --> 00:42:41,236
But there was an opportunity
for refinement here.

995
00:42:41,366 --> 00:42:43,586
Before in the previous
example, I had render header

996
00:42:43,586 --> 00:42:45,756
and render footer, and why is

997
00:42:45,756 --> 00:42:47,216
that arguably not
the best design?

998
00:42:47,216 --> 00:42:47,283
Yeah.

999
00:42:47,456 --> 00:42:52,856
>> Well you could just do
one function called render

1000
00:42:52,856 --> 00:42:54,236
and then passing what
you want to render.

1001
00:42:54,236 --> 00:42:54,946
>> Exactly, right.

1002
00:42:54,946 --> 00:42:55,636
So this isn't horrible.

1003
00:42:55,636 --> 00:42:57,866
But the moment I introduce
like a render middle,

1004
00:42:58,006 --> 00:42:59,886
or a render top right function,

1005
00:42:59,886 --> 00:43:03,096
or more increasingly specific
rendering functions feels

1006
00:43:03,096 --> 00:43:05,046
like there's an opportunity
to factor that code out

1007
00:43:05,046 --> 00:43:07,806
and generalize it as just
a generic render function.

1008
00:43:08,026 --> 00:43:11,256
So recall that in version
three, we did exactly that.

1009
00:43:11,256 --> 00:43:13,806
In helpers.php, I
just trimmed my code,

1010
00:43:13,946 --> 00:43:16,086
added a couple new
features here,

1011
00:43:16,276 --> 00:43:18,176
so that render now
takes two arguments,

1012
00:43:18,176 --> 00:43:20,356
the name of the template
so to speak to render,

1013
00:43:20,446 --> 00:43:23,276
the view so to speak,
and then it,

1014
00:43:23,276 --> 00:43:26,456
it renders that particular
template by passing

1015
00:43:26,456 --> 00:43:27,886
in the data that was given.

1016
00:43:28,116 --> 00:43:29,316
So a little sanity check here.

1017
00:43:29,316 --> 00:43:31,736
First, I'm figuring out
the path to the file

1018
00:43:31,976 --> 00:43:33,946
and why am I doing
this first line?

1019
00:43:34,186 --> 00:43:38,716
Dollar sign path
equals template.php.

1020
00:43:38,716 --> 00:43:42,466
Why not just force the caller to
specify header.php, footer.php?

1021
00:43:42,466 --> 00:43:42,566
Yeah.

1022
00:43:42,566 --> 00:43:43,076
>> To save space.

1023
00:43:43,076 --> 00:43:45,506
It's easier to type
render header,

1024
00:43:50,116 --> 00:43:50,786
instead render header.php.

1025
00:43:50,786 --> 00:43:51,286
>> Yeah. Exactly.

1026
00:43:51,286 --> 00:43:51,856
As simple as that.

1027
00:43:51,856 --> 00:43:54,986
Rather than saying render
header.php, it's just reasonable

1028
00:43:54,986 --> 00:43:57,596
to just want to say
render "header."

1029
00:43:57,936 --> 00:43:58,406
What else?

1030
00:43:58,406 --> 00:44:01,426
If I ever change the
languages that I am using

1031
00:44:01,426 --> 00:44:03,106
for my templates; for instance,

1032
00:44:03,106 --> 00:44:04,866
I want to support a
templating engine,

1033
00:44:05,156 --> 00:44:06,856
there exists things
called Smarty.

1034
00:44:06,856 --> 00:44:09,656
There are other templating
engines that give you all sorts

1035
00:44:09,656 --> 00:44:11,006
of functionality in your views.

1036
00:44:11,206 --> 00:44:13,756
We're not getting their
yet, but it'd be nice if I

1037
00:44:13,756 --> 00:44:15,796
at least can support
different types of templates

1038
00:44:15,796 --> 00:44:17,946
and let the function
figure out what they are.

1039
00:44:18,156 --> 00:44:19,546
So in short, I'm just
checking to make sure

1040
00:44:19,546 --> 00:44:22,866
that the path then exists
after appending the dot PHP,

1041
00:44:22,866 --> 00:44:25,116
then I do the exact
same thing as before.

1042
00:44:25,506 --> 00:44:28,856
So we then clean things up
ever so slightly further.

1043
00:44:28,856 --> 00:44:30,616
That was version three.

1044
00:44:30,616 --> 00:44:33,946
If we go into four, notice
what we introduced this time.

1045
00:44:34,416 --> 00:44:37,476
Why did I introduce these
subdirectories here?

1046
00:44:37,976 --> 00:44:41,096
I claim that it's an improvement

1047
00:44:41,376 --> 00:44:43,216
by organizing things
in subdirectories.

1048
00:44:43,446 --> 00:44:45,976
But why is this compelling?

1049
00:44:45,976 --> 00:44:46,066
Yeah.

1050
00:44:46,846 --> 00:44:50,586
>> I don't know exactly if
this applies in this example,

1051
00:44:50,586 --> 00:44:55,416
but you should really keep all
your files in other directories

1052
00:44:55,416 --> 00:44:58,596
that the, that the
client can visit directly.

1053
00:44:58,786 --> 00:44:59,456
>> Exactly.

1054
00:44:59,456 --> 00:45:01,726
So this was a step toward
a better security model

1055
00:45:01,726 --> 00:45:02,246
to be honest.

1056
00:45:02,246 --> 00:45:03,556
This isn't all the way there.

1057
00:45:03,556 --> 00:45:05,636
This is only a, a
half a step toward it.

1058
00:45:05,986 --> 00:45:08,236
But I've organized
now my templates

1059
00:45:08,236 --> 00:45:09,856
into literally a
templates directory.

1060
00:45:09,856 --> 00:45:12,066
This would often be called
the views directory as well.

1061
00:45:12,506 --> 00:45:15,876
And the motivation there being
the user should never really

1062
00:45:15,876 --> 00:45:18,556
visit footer.php or
header.php directly.

1063
00:45:18,736 --> 00:45:21,736
Why? Well they're going to get
a partial page, either the top

1064
00:45:21,736 --> 00:45:22,886
or the bottom and nothing else.

1065
00:45:22,886 --> 00:45:25,766
So I just, just don't want them
visiting that in principal.

1066
00:45:25,966 --> 00:45:28,806
And then helpers.php, similarly,
I don't want them visiting

1067
00:45:28,806 --> 00:45:31,656
that file either because it
just has helper functions.

1068
00:45:31,656 --> 00:45:34,206
It's not going to actually spit
anything out, and worst case,

1069
00:45:34,206 --> 00:45:35,936
maybe I have some passwords
or something in there,

1070
00:45:36,106 --> 00:45:37,816
and I don't want the
risk of them visiting

1071
00:45:37,816 --> 00:45:39,576
that file directly, so
I'm going to tuck it

1072
00:45:39,576 --> 00:45:41,126
into a directory
called includes.

1073
00:45:41,406 --> 00:45:45,766
Now this does not
necessarily protect us fully.

1074
00:45:45,766 --> 00:45:48,206
As an aside, recall that Apache

1075
00:45:48,276 --> 00:45:51,936
and other web servers support
configuration files inside

1076
00:45:51,936 --> 00:45:55,046
individual directories, so
I could, if I really want

1077
00:45:55,046 --> 00:45:58,816
to be clever, have an HT
access file in my directory,

1078
00:45:58,816 --> 00:46:00,366
in my public HTML directory

1079
00:46:00,546 --> 00:46:03,636
that says do not let the
outside world into includes

1080
00:46:03,826 --> 00:46:04,966
or the templates directory.

1081
00:46:05,286 --> 00:46:07,126
But the risk there is
that if I screw up,

1082
00:46:07,126 --> 00:46:10,456
if the webmaster disables HT
access files, all of the sudden

1083
00:46:10,456 --> 00:46:11,686
that protection could be lost.

1084
00:46:11,986 --> 00:46:15,946
So a better approach is what
we did half a step later.

1085
00:46:15,946 --> 00:46:18,226
So that was version four,
and in version five,

1086
00:46:18,226 --> 00:46:23,906
what I instead did was
opened, was this layout.

1087
00:46:24,846 --> 00:46:27,826
I created a whole new level

1088
00:46:27,826 --> 00:46:31,166
of hierarchy whereby I still
had my includes folder,

1089
00:46:31,276 --> 00:46:35,416
I still had my templates folder,
but what's different this time,

1090
00:46:35,606 --> 00:46:37,026
versus the previous example?

1091
00:46:37,616 --> 00:46:37,696
Yeah.

1092
00:46:39,516 --> 00:46:43,546
[ Inaudible ]

1093
00:46:44,046 --> 00:46:47,486
Exactly. Now I have an HTML
directory, the idea of which is

1094
00:46:47,486 --> 00:46:51,566
that only the web accessible
stuff including not just my PHP

1095
00:46:51,596 --> 00:46:54,546
files, but my gifs, my jpegs,
java scripts, CSS, all the stuff

1096
00:46:54,546 --> 00:46:57,746
that has to be public,
goes into that directory.

1097
00:46:57,746 --> 00:46:59,006
Or not even necessarily public,

1098
00:46:59,206 --> 00:47:02,446
has to be uniquely addressable
via a URL in the browser

1099
00:47:02,446 --> 00:47:03,996
so that the user can
actually visit it.

1100
00:47:04,276 --> 00:47:07,456
Now recall last week our
discussion of http.conf.

1101
00:47:07,896 --> 00:47:12,176
So recall that that has a, a
directive called document root.

1102
00:47:12,576 --> 00:47:17,256
So let me go ahead and open
that at c:httpdhttp.conf

1103
00:47:18,126 --> 00:47:20,296
and let me scroll
down to document root.

1104
00:47:20,996 --> 00:47:23,336
Recall this thing that
we looked at last time

1105
00:47:23,976 --> 00:47:28,816
where we had this directive
here, var, www, html.

1106
00:47:29,126 --> 00:47:33,306
So this is that document
root we keep alluding to.

1107
00:47:33,306 --> 00:47:37,636
This is why we had to put
that silly little index.html

1108
00:47:37,636 --> 00:47:39,326
in that folder last week.

1109
00:47:39,606 --> 00:47:43,976
Well okay, how do I now
make this particular example

1110
00:47:43,976 --> 00:47:45,056
accessible on the web.

1111
00:47:45,416 --> 00:47:47,246
Well I would have
to do something now

1112
00:47:47,246 --> 00:47:55,656
like document roots, home,
jharvard, publichtml, html,

1113
00:47:56,166 --> 00:47:58,276
but this isn't quite
right, right?

1114
00:47:58,276 --> 00:48:00,526
Because if I do this
for my document root,

1115
00:48:01,006 --> 00:48:03,916
specifying that this
html directory is the one

1116
00:48:03,916 --> 00:48:06,366
that should define the
base of the web server,

1117
00:48:06,366 --> 00:48:07,586
you can't go any
higher than that.

1118
00:48:07,586 --> 00:48:08,746
That's what the document
root does.

1119
00:48:08,746 --> 00:48:11,276
It means you can go to that
folder and anything in it,

1120
00:48:11,536 --> 00:48:12,486
but you can't go higher.

1121
00:48:12,486 --> 00:48:14,426
And that's exactly the
protection we want.

1122
00:48:14,936 --> 00:48:17,146
I'm kind of being an idiot
here there, though, right.

1123
00:48:17,146 --> 00:48:19,746
I haven't really achieved
what I want to achieve.

1124
00:48:19,806 --> 00:48:20,876
Why? Yeah.

1125
00:48:21,496 --> 00:48:24,236
>> By default, it's
a public html.

1126
00:48:24,456 --> 00:48:28,366
>> Right. So by default, public
html, is literally public.

1127
00:48:28,366 --> 00:48:30,106
So you can create as much
hierarchy inside of it

1128
00:48:30,106 --> 00:48:32,816
as you want, the world can
still access the contents

1129
00:48:32,816 --> 00:48:33,656
of that directory.

1130
00:48:33,936 --> 00:48:36,506
So unfortunately, when
you're on a shared web post

1131
00:48:36,506 --> 00:48:39,746
that gives just a home page with
a tilde involved in the URL,

1132
00:48:39,746 --> 00:48:42,606
like tilde jharvard, you
cannot achieve this sort

1133
00:48:42,606 --> 00:48:45,486
of ideal security model,
because all of your files

1134
00:48:45,486 --> 00:48:47,316
by nature have to be public.

1135
00:48:47,476 --> 00:48:50,166
So instead, we need to have
either a better web post

1136
00:48:50,166 --> 00:48:53,026
or our own administrative
access to the machine

1137
00:48:53,236 --> 00:48:56,636
so we can configure this
a little more properly.

1138
00:48:56,896 --> 00:49:00,306
So for instance, what I really
want to do now is I'm going

1139
00:49:00,306 --> 00:49:01,376
to propose the following.

1140
00:49:01,376 --> 00:49:05,476
Let's steal an idea from lecture
zero this summer whereby we

1141
00:49:05,476 --> 00:49:07,216
implement our own virtual hosts.

1142
00:49:07,216 --> 00:49:08,256
And I'm going to
say you know what,

1143
00:49:08,256 --> 00:49:09,726
rather than use publichtml,

1144
00:49:10,006 --> 00:49:13,676
let me give jharvard a vhosts
directory, for virtual hosts,

1145
00:49:13,986 --> 00:49:16,816
and in there, I'm going to
give him the added ability

1146
00:49:16,816 --> 00:49:20,856
to do something like
this, project zero/html.

1147
00:49:21,466 --> 00:49:23,126
In other words, I'm
going to propose

1148
00:49:23,126 --> 00:49:25,286
that we configure the
server in such a way

1149
00:49:25,596 --> 00:49:28,486
that John Harvard can create
a vhost directory inside

1150
00:49:28,486 --> 00:49:31,386
of which he can, he can create a
project directory, project zero,

1151
00:49:31,386 --> 00:49:33,326
project one, project
two, fubar, bass,

1152
00:49:33,326 --> 00:49:35,096
doesn't matter what he
wants to call the project.

1153
00:49:35,726 --> 00:49:38,066
All of his code can then
go in this directory.

1154
00:49:38,256 --> 00:49:40,206
And if you want to
secure your website

1155
00:49:40,256 --> 00:49:42,926
in this more optimal
fashion, you just make sure

1156
00:49:42,926 --> 00:49:46,276
that the web accessible stuff
goes in the html directory,

1157
00:49:46,376 --> 00:49:47,836
and your includes directory,

1158
00:49:47,836 --> 00:49:49,526
and your templates
directory go where?

1159
00:49:49,526 --> 00:49:52,396
In here? Or in here?

1160
00:49:52,496 --> 00:49:54,346
A or, A or B?

1161
00:49:54,576 --> 00:49:54,646
>> B.

1162
00:49:54,646 --> 00:49:55,746
>> Okay. B. Right.

1163
00:49:55,746 --> 00:49:57,436
You want them at the same level

1164
00:49:57,436 --> 00:50:00,556
as the html directory,
not inside of it.

1165
00:50:00,996 --> 00:50:02,296
Now there's a problem here.

1166
00:50:02,296 --> 00:50:05,906
If I have to edit my web
server's configuration

1167
00:50:05,906 --> 00:50:09,016
for every project
this summer, every,

1168
00:50:09,086 --> 00:50:10,956
when we get to project
one, what's going to break?

1169
00:50:11,676 --> 00:50:12,336
Project zero.

1170
00:50:12,336 --> 00:50:13,706
When we get to project
two, what's going to break?

1171
00:50:13,946 --> 00:50:15,046
Project one, right.

1172
00:50:15,046 --> 00:50:16,166
Because, if we keep
changing this.

1173
00:50:16,166 --> 00:50:19,486
And a web server by nature can
only have one document root.

1174
00:50:19,706 --> 00:50:21,826
However, there is a way
we can work around this.

1175
00:50:21,826 --> 00:50:25,386
Let me undo these
changes and let me open

1176
00:50:25,386 --> 00:50:27,606
up a file whose name
is going to change

1177
00:50:27,606 --> 00:50:29,906
by the time the appliance
is posted tomorrow.

1178
00:50:29,906 --> 00:50:32,426
But I'm going to go in there
temporarily to its current name,

1179
00:50:32,886 --> 00:50:37,646
let's go into httpconf.d
and pull

1180
00:50:37,646 --> 00:50:39,166
up this temporary file here.

1181
00:50:39,166 --> 00:50:39,576
Whoops.

1182
00:50:45,676 --> 00:50:46,606
Let's look at this file.

1183
00:50:46,886 --> 00:50:51,616
So this is another; this
is a modified http.conf--

1184
00:50:51,666 --> 00:50:53,926
let me zoom back in
to make it larger.

1185
00:50:54,216 --> 00:50:55,696
That does a few things for us.

1186
00:50:55,896 --> 00:50:58,006
So let's focus on
the juicy part first.

1187
00:50:58,006 --> 00:51:01,846
In line 7, we have the
following comment that I wrote,

1188
00:51:01,846 --> 00:51:05,146
virtual host will override
http.conf defaults.

1189
00:51:05,556 --> 00:51:06,616
So what is this saying?

1190
00:51:06,616 --> 00:51:08,596
Well, name virtual
host, whatever that is,

1191
00:51:08,596 --> 00:51:11,376
virtual host *80, whatever
that is, UseCanonicalName,

1192
00:51:11,376 --> 00:51:13,726
whatever that is, and then
it starts to get interesting.

1193
00:51:13,726 --> 00:51:17,816
And the most interesting line
is 20; 20 is saying that rather

1194
00:51:17,816 --> 00:51:20,856
than define one document
root for the entire server,

1195
00:51:21,056 --> 00:51:24,666
let's define a virtual
document root dynamically

1196
00:51:24,936 --> 00:51:27,326
by using essentially a variable.

1197
00:51:27,806 --> 00:51:30,746
So notice what I've done here
is I'm saying always look

1198
00:51:30,746 --> 00:51:34,796
in home jharvard vhosts for your
virtual hosts on this server,

1199
00:51:35,256 --> 00:51:37,646
but this name here
can actually vary.

1200
00:51:37,726 --> 00:51:40,276
It can be project zero, it can
be project one, project two,

1201
00:51:40,276 --> 00:51:44,276
fubar, bass, whatever you want,
but thereafter always dive

1202
00:51:44,276 --> 00:51:47,266
into an html directory
for security sake.

1203
00:51:47,776 --> 00:51:47,916
Yeah.

1204
00:51:48,196 --> 00:51:51,206
>> So that means we have
[inaudible] the number

1205
00:51:51,326 --> 00:51:52,996
of instances for
the [inaudible]?

1206
00:51:52,996 --> 00:51:53,946
>> Can you say that again?

1207
00:51:54,666 --> 00:51:58,286
>> So we are creating
the instances

1208
00:51:58,286 --> 00:51:59,876
of [inaudible], I mean, Apache?

1209
00:51:59,876 --> 00:52:03,216
>> So this will be, this file
will be prefigured for you

1210
00:52:03,216 --> 00:52:07,116
but what it's doing is giving
John Harvard specifically the

1211
00:52:07,116 --> 00:52:08,676
ability to have an
infinite number

1212
00:52:08,676 --> 00:52:10,696
of virtual hosts on the server.

1213
00:52:10,926 --> 00:52:13,136
So there is one weakness
here in that it is hardcoded

1214
00:52:13,136 --> 00:52:15,886
for John Harvard, however if we
really put some effort into it,

1215
00:52:16,096 --> 00:52:18,386
we could generalize this
further for multiple users.

1216
00:52:18,386 --> 00:52:19,936
But for now, we just
need a single user

1217
00:52:19,936 --> 00:52:24,576
on this particular VM and the
key is that $zero can take,

1218
00:52:24,576 --> 00:52:27,266
can represent any
directory that we create

1219
00:52:27,266 --> 00:52:28,746
in that vhost directory.

1220
00:52:29,106 --> 00:52:31,886
Meanwhile, recall that
we saw a logs directory

1221
00:52:31,886 --> 00:52:33,026
in John Harvard's directory.

1222
00:52:33,026 --> 00:52:34,076
Why is that there?

1223
00:52:34,236 --> 00:52:37,116
Typically logs are
somewhere on the file system,

1224
00:52:37,346 --> 00:52:38,856
but for convenience,
pedagogically,

1225
00:52:38,856 --> 00:52:40,966
if you want to be able to
access your web server log,

1226
00:52:40,966 --> 00:52:42,026
see where you messed up,

1227
00:52:42,056 --> 00:52:43,466
see what the error
message actually is,

1228
00:52:43,746 --> 00:52:47,236
we've simply told the server,
Apache, put logs instead

1229
00:52:47,236 --> 00:52:50,556
in jharvard's home directory,
in a folder called logs,

1230
00:52:50,556 --> 00:52:51,866
so that they're accessible
to you.

1231
00:52:52,246 --> 00:52:54,966
And then up here, we see a
little familiarity syntax.

1232
00:52:54,966 --> 00:52:56,506
Eighty is referring
to what, probably?

1233
00:52:57,876 --> 00:52:58,036
Yeah.

1234
00:52:58,346 --> 00:52:58,916
>> Port 80.

1235
00:52:59,076 --> 00:53:03,256
>> Port 80, which is http,
the star represents anything

1236
00:53:03,256 --> 00:53:08,126
and what it means here is any IP
address or any name, so fubar,

1237
00:53:08,126 --> 00:53:09,686
bass, project zero, project 1,

1238
00:53:09,946 --> 00:53:12,736
and then named virtual host is
just a directive that you need

1239
00:53:12,736 --> 00:53:16,646
to include when you want to
enable virtual hosting based

1240
00:53:16,646 --> 00:53:19,646
on names in the first
place, where the name is in,

1241
00:53:19,806 --> 00:53:22,966
inferred from that,
that host header

1242
00:53:23,076 --> 00:53:25,156
that you get from the browser.

1243
00:53:25,486 --> 00:53:27,546
So what does this
mean in real terms?

1244
00:53:27,546 --> 00:53:32,156
Well let me go over here into
the appliance and let me pull

1245
00:53:32,156 --> 00:53:35,536
up John Harvard's home
directory, which again has this.

1246
00:53:35,876 --> 00:53:38,666
And let me go ahead and make
a directory called vhosts

1247
00:53:39,026 --> 00:53:42,416
and let me chmod at 711 so
that the world can get in there

1248
00:53:42,416 --> 00:53:43,456
but can't poke around.

1249
00:53:44,226 --> 00:53:50,316
Let me then make a
directory called project zero,

1250
00:53:50,416 --> 00:53:54,456
and let me go ahead and chmod
that, and then let me go ahead

1251
00:53:54,456 --> 00:53:56,156
and make a directory, html,

1252
00:53:56,156 --> 00:53:57,736
and notice I'm doing
this very quickly

1253
00:53:57,736 --> 00:53:59,276
by scrolling up and down.

1254
00:53:59,276 --> 00:54:01,476
You can go through your history
with your up and down arrows.

1255
00:54:01,836 --> 00:54:05,216
So let me go ahead and make
this file, this folder,

1256
00:54:05,736 --> 00:54:10,446
and then chmod it 711, so now,
we have a vhost directory,

1257
00:54:10,696 --> 00:54:13,316
a project zero directory,
and an html directory,

1258
00:54:13,556 --> 00:54:14,816
and let's just do this here.

1259
00:54:14,816 --> 00:54:20,716
So, geany index.html,
I am in here.

1260
00:54:20,956 --> 00:54:23,706
So it's not actually html, but
that will suffice for a test.

1261
00:54:23,956 --> 00:54:25,456
Let me do an LS-L.

1262
00:54:25,946 --> 00:54:26,846
What command should I type

1263
00:54:26,846 --> 00:54:28,496
to make sure this
actually world readable?

1264
00:54:28,496 --> 00:54:29,196
>> Chmod 644.

1265
00:54:34,416 --> 00:54:38,746
>> Good chmod 644, or I
could do the simpler A plus R

1266
00:54:38,746 --> 00:54:40,166
to give everyone
read privileges.

1267
00:54:40,426 --> 00:54:43,286
LS-L now confirms that
this seems to be correct.

1268
00:54:43,856 --> 00:54:46,536
So now let's go over
to my browser

1269
00:54:46,726 --> 00:54:51,436
and do http://project
zero/ enter.

1270
00:54:52,676 --> 00:54:56,416
Problem. Chrome was
trying to being helpful,

1271
00:54:56,416 --> 00:54:58,486
it thinks project
zero.biz exists

1272
00:54:58,486 --> 00:55:00,576
or .us, but clearly wrong.

1273
00:55:01,396 --> 00:55:03,516
What's broken here?

1274
00:55:04,106 --> 00:55:07,466
Got to integrate everything
we've talked about thus far,

1275
00:55:07,466 --> 00:55:08,656
from lecture zero onward.

1276
00:55:15,316 --> 00:55:15,636
>> [Inaudible] host file?

1277
00:55:15,636 --> 00:55:17,696
>> Yeah. Something
about the host file.

1278
00:55:17,696 --> 00:55:20,546
So even if you're not familiar
with that, roll back your mind

1279
00:55:20,606 --> 00:55:23,696
to lecture zero when we talked
about DNS and we told the story

1280
00:55:23,886 --> 00:55:26,486
of going from my laptop
to Google.com and back

1281
00:55:26,486 --> 00:55:27,966
and the various steps involved.

1282
00:55:27,966 --> 00:55:29,106
And one of the first steps was,

1283
00:55:29,336 --> 00:55:30,826
involved in that
process was what?

1284
00:55:31,596 --> 00:55:32,696
>> Well you can give your,

1285
00:55:33,046 --> 00:55:35,836
you can give your local
host a name, so...

1286
00:55:36,076 --> 00:55:38,056
>> Good. And let me
answer the first question,

1287
00:55:38,056 --> 00:55:39,796
so one of the steps
involved was DNS

1288
00:55:40,456 --> 00:55:43,986
because what's happening here
is I've presumptuously created a

1289
00:55:43,986 --> 00:55:46,106
folder, a vhost called
project zero,

1290
00:55:46,266 --> 00:55:48,216
but I haven't told the world
about it, so I either need

1291
00:55:48,216 --> 00:55:51,156
to go buy a domain name named
project zero, and that's it,

1292
00:55:51,156 --> 00:55:52,746
and that's not very realistic.

1293
00:55:52,936 --> 00:55:56,256
Or I at least need to trick
my own computer, the appliance

1294
00:55:56,256 --> 00:55:57,886
in this case, into thinking

1295
00:55:57,886 --> 00:56:01,246
that a project zero
domain name exists.

1296
00:56:01,686 --> 00:56:04,116
Now I can do this in a
very heavy-handed approach

1297
00:56:04,116 --> 00:56:06,446
by actually editing a
DNS server somewhere

1298
00:56:06,446 --> 00:56:08,406
on Harvard's network
or on my computer.

1299
00:56:08,556 --> 00:56:10,886
But we can do this more
simply in a Linux computer,

1300
00:56:10,886 --> 00:56:12,216
or MAC OS, or Windows.

1301
00:56:12,216 --> 00:56:14,156
There's generally a
text file you can edit

1302
00:56:14,336 --> 00:56:15,456
that allows you to do this.

1303
00:56:15,456 --> 00:56:18,636
So I'm going to type sudo,
which is substitute user do,

1304
00:56:19,026 --> 00:56:22,786
and that means run this command
as an administrator by default

1305
00:56:22,786 --> 00:56:26,046
and I'm going to go
ahead and open up etsy

1306
00:56:26,116 --> 00:56:31,516
for et cetera hosts, enter
and that's going to go ahead

1307
00:56:31,516 --> 00:56:34,156
and open up this file, which
looks like this by default.

1308
00:56:34,516 --> 00:56:38,416
So by default, a computer
typically has an IP address

1309
00:56:38,506 --> 00:56:39,816
that's not public at all.

1310
00:56:39,816 --> 00:56:41,336
It's called the loop
back address,

1311
00:56:41,716 --> 00:56:46,276
and it is always 127.0.0.1, and
that is an IP address that all

1312
00:56:46,276 --> 00:56:48,696
of your computers have
that refers to itself.

1313
00:56:48,866 --> 00:56:51,076
So it's a loop back in
that recursive sense.

1314
00:56:51,496 --> 00:56:55,816
So if I want to create a
project zero host name,

1315
00:56:56,066 --> 00:56:57,466
I can actually just
say, alright,

1316
00:56:57,636 --> 00:57:00,886
well associate the
project zero host name

1317
00:57:01,026 --> 00:57:02,436
with that same IP address.

1318
00:57:02,676 --> 00:57:05,866
Create an alias for my current
computer that's not just called

1319
00:57:05,866 --> 00:57:07,826
a local host, that's
not called appliance,

1320
00:57:07,826 --> 00:57:10,966
which we the staff created, but
it's also called project zero.

1321
00:57:10,966 --> 00:57:12,336
These are all just now synonyms.

1322
00:57:12,696 --> 00:57:16,976
So now let me go to my browser
and reload this, and voila,

1323
00:57:17,316 --> 00:57:19,396
project zero is born
on the Internet.

1324
00:57:19,596 --> 00:57:20,596
Well not really the Internet.

1325
00:57:20,596 --> 00:57:21,926
Who else in the world
can see this?

1326
00:57:23,316 --> 00:57:24,436
No one at the moment, right?

1327
00:57:24,436 --> 00:57:26,586
We're not only within the
confines of my browser,

1328
00:57:26,586 --> 00:57:28,706
we're also within the
confines of the appliance,

1329
00:57:29,016 --> 00:57:31,756
and it's the only etsy
host file in the world

1330
00:57:31,896 --> 00:57:33,896
that has this change
right now, at least.

1331
00:57:34,006 --> 00:57:36,286
So what happens is that
very first story we told

1332
00:57:36,286 --> 00:57:39,066
in lecture zero about my
computer asks the browser,

1333
00:57:39,066 --> 00:57:42,356
asks the operating system, asks
the world, for the IP address

1334
00:57:42,396 --> 00:57:43,926
of the host name
that I've typed in,

1335
00:57:44,186 --> 00:57:46,776
now Linux in this case
intervenes and says,

1336
00:57:46,776 --> 00:57:48,996
oh wait a minute, I have that
answer for you right here

1337
00:57:48,996 --> 00:57:50,536
in this text file
called etsy hosts.

1338
00:57:50,536 --> 00:57:54,306
Use 127.0.0.1 and
then meanwhile,

1339
00:57:54,466 --> 00:57:57,286
how does the web
server know which vhost

1340
00:57:57,886 --> 00:58:02,166
to serve index.html for,
because suppose I had project 1

1341
00:58:02,166 --> 00:58:04,716
and project 2, how
does the browser know?

1342
00:58:05,186 --> 00:58:12,686
>> But wait, actually, didn't
you put inside the project zero,

1343
00:58:12,686 --> 00:58:13,866
I am in here, not
tell the world?

1344
00:58:13,866 --> 00:58:14,376
>> Oh I did.

1345
00:58:14,376 --> 00:58:16,776
Damnit. [Laughter]
Very good point.

1346
00:58:17,946 --> 00:58:20,976
That is because, okay,
standby; well played.

1347
00:58:21,546 --> 00:58:24,746
I had disabled this
before class.

1348
00:58:25,166 --> 00:58:28,806
Notice when you rename a file
to .off, that usually breaks it.

1349
00:58:29,436 --> 00:58:32,286
So let me get rid of
that, and now let me do,

1350
00:58:32,286 --> 00:58:33,366
service, hdpd, restart.

1351
00:58:33,366 --> 00:58:38,186
You almost let me
get away with that.

1352
00:58:39,336 --> 00:58:39,936
How's that?

1353
00:58:40,076 --> 00:58:42,196
Alright. So now the
story is correct.

1354
00:58:43,056 --> 00:58:49,346
So, how does not Apache know
which vhost directory to go

1355
00:58:49,346 --> 00:58:52,006
into to get me an
index.html file?

1356
00:58:52,486 --> 00:58:53,866
Where is that information
coming from?

1357
00:58:54,146 --> 00:58:57,736
>> So it's that same [inaudible]
you showed us a few moments

1358
00:58:58,596 --> 00:59:02,806
before with the virtual
host and the [inaudible].

1359
00:59:03,056 --> 00:59:04,866
>> Okay, from, to
some project zero.

1360
00:59:04,866 --> 00:59:08,326
But how does the server know
what vhost was requested?

1361
00:59:08,926 --> 00:59:10,666
Thinking back to lecture zero.

1362
00:59:10,666 --> 00:59:12,896
>> The git request.

1363
00:59:12,986 --> 00:59:13,976
>> The git request.

1364
00:59:14,186 --> 00:59:17,036
So because we've only defined
one vhost now, in fairness,

1365
00:59:17,386 --> 00:59:19,776
but in a minute I could
create project 1, project 2,

1366
00:59:19,776 --> 00:59:21,596
I just have to type
makedir a bunch of times.

1367
00:59:21,936 --> 00:59:24,566
So recall that multiple
host names can live

1368
00:59:24,566 --> 00:59:25,546
at the same IP address.

1369
00:59:25,966 --> 00:59:27,986
And this is true in the
web hosting world and also

1370
00:59:27,986 --> 00:59:30,276
in our little fake world of the
appliance where we're pretending

1371
00:59:30,276 --> 00:59:32,566
to be a web hosting
company with one IP address

1372
00:59:32,566 --> 00:59:33,686
and multiple host names.

1373
00:59:33,956 --> 00:59:35,726
So how, where is
that coming from?

1374
00:59:35,966 --> 00:59:38,306
Well let me open Chrome's
developer tool bar.

1375
00:59:38,676 --> 00:59:41,336
Let me open up the network
tab as we've done before.

1376
00:59:41,496 --> 00:59:45,836
Let me reload this page,
click on here, and actually...

1377
00:59:45,836 --> 00:59:49,716
Oh, actually as a development
tip, notice that I got 304,

1378
00:59:49,716 --> 00:59:51,706
which does not sound
good, I wanted to get 200.

1379
00:59:51,916 --> 00:59:53,156
That's just because of caching.

1380
00:59:53,156 --> 00:59:55,106
The webserver said, mmm-mm,
you already got this from me,

1381
00:59:55,106 --> 00:59:56,596
it hasn't changed,
keep the copy you have.

1382
00:59:57,056 --> 00:59:59,496
So I'm going to instead
hold shift and reload

1383
00:59:59,496 --> 01:00:01,036
in general clearing your cache

1384
01:00:01,036 --> 01:00:03,136
or holding shift is your
friend with many browsers.

1385
01:00:03,466 --> 01:00:05,606
Now I get a 200 and what I care

1386
01:00:05,606 --> 01:00:10,476
about here is the request
headers which has this key line,

1387
01:00:10,766 --> 01:00:12,986
reminding the server
what host was requested.

1388
01:00:13,256 --> 01:00:15,146
So we've come full
circle to lecture zero.

1389
01:00:15,146 --> 01:00:16,916
We've told the DNS
server story then,

1390
01:00:17,156 --> 01:00:19,426
now we've actually
hijacked the DNS story

1391
01:00:19,426 --> 01:00:21,886
to insert our own
answers to DNS queries.

1392
01:00:22,156 --> 01:00:23,566
So why is this useful?

1393
01:00:23,566 --> 01:00:24,386
Why is this relevant?

1394
01:00:24,516 --> 01:00:26,616
Well one, as a developer,
it's going to allow you

1395
01:00:26,616 --> 01:00:28,906
for the course of the summer to
create three different projects

1396
01:00:28,906 --> 01:00:32,616
on the same server in the same
master directory without having

1397
01:00:32,616 --> 01:00:34,876
to create like three different
appliances or something crazy

1398
01:00:34,876 --> 01:00:38,126
like that, or without having to
turn off project zero to turn

1399
01:00:38,126 --> 01:00:39,716
on project 1 and so forth,

1400
01:00:39,716 --> 01:00:42,056
and plus this is also
wonderfully representative

1401
01:00:42,196 --> 01:00:44,036
of exactly what you
would find on a VPS,

1402
01:00:44,396 --> 01:00:45,946
a virtual private
server out there

1403
01:00:46,306 --> 01:00:49,676
if they do support
virtual hosts in this way,

1404
01:00:49,676 --> 01:00:51,996
and they don't force you
to have a URL with a tilde.

1405
01:00:52,256 --> 01:00:54,936
So even though we started
the story with public html

1406
01:00:55,076 --> 01:00:57,976
and tilde jharvard in the
URL, that's a hideous URL.

1407
01:00:57,976 --> 01:01:01,216
Plus, it does not let us
implement this more security

1408
01:01:01,216 --> 01:01:02,846
conscious directory structure.

1409
01:01:03,076 --> 01:01:06,726
So as you'll see in the spec for
the project zero and 1 and 2,

1410
01:01:06,946 --> 01:01:10,246
you will be asked to make sure
your site works within a vhost

1411
01:01:10,246 --> 01:01:11,786
like this, which is perfect

1412
01:01:11,786 --> 01:01:13,186
because this is the
way it should be done

1413
01:01:13,426 --> 01:01:14,886
in the real world anyway.

1414
01:01:15,436 --> 01:01:18,516
The only customization we've
done is just move the vhost

1415
01:01:18,516 --> 01:01:21,566
directory into John
Harvard's home directory just

1416
01:01:21,566 --> 01:01:22,916
so that it's easily accessible,

1417
01:01:22,916 --> 01:01:24,326
instead of being
hidden somewhere else

1418
01:01:24,326 --> 01:01:25,176
on the file system.

1419
01:01:25,176 --> 01:01:27,906
Phew. That was a lot.

1420
01:01:29,056 --> 01:01:29,786
Any questions?

1421
01:01:30,976 --> 01:01:35,016
Alright, let's take our MVC one
step further before we take a

1422
01:01:35,016 --> 01:01:37,566
break and then come back on XML.

1423
01:01:37,846 --> 01:01:42,646
So let me go into the code
that we've been looking at,

1424
01:01:43,096 --> 01:01:45,526
and I think we left
off with five here.

1425
01:01:45,526 --> 01:01:48,396
Yep. Which we had this
directory structure.

1426
01:01:48,396 --> 01:01:50,186
So the website itself
aesthetically is not

1427
01:01:50,186 --> 01:01:50,786
at all different.

1428
01:01:50,786 --> 01:01:52,826
All we've been doing is
hammering on the design.

1429
01:01:53,156 --> 01:01:55,736
So let me now go into the
sixth iteration of this

1430
01:01:56,156 --> 01:01:59,886
where I do this layout.

1431
01:02:00,466 --> 01:02:02,896
Pretty much the same, but
I've decided, you know what,

1432
01:02:02,896 --> 01:02:04,886
I'm going to have some best
practices here and I'm going

1433
01:02:04,886 --> 01:02:07,916
to create a views directory
which represents all

1434
01:02:07,916 --> 01:02:09,966
of the aesthetics of
my site and I'm going

1435
01:02:09,966 --> 01:02:12,416
to introduce a slightly
different version of index.php

1436
01:02:12,576 --> 01:02:15,556
that I'm going to start
calling the controller.

1437
01:02:15,936 --> 01:02:19,626
So in this model here,
we now have much closer

1438
01:02:19,626 --> 01:02:21,546
to a true MVC architecture.

1439
01:02:21,816 --> 01:02:24,256
Still no M, no models just yet.

1440
01:02:24,256 --> 01:02:27,186
It's all static content,
but now I have a controller

1441
01:02:27,286 --> 01:02:30,296
and then most everything
else in the, everything else

1442
01:02:30,296 --> 01:02:32,646
in the views directory
is the V in the MVC.

1443
01:02:32,866 --> 01:02:35,056
So let's take a look
at how this works

1444
01:02:35,056 --> 01:02:38,566
and why this design is a
little bit cleaner still.

1445
01:02:38,876 --> 01:02:42,986
In my HTML directory, there's
nothing now except index.php.

1446
01:02:42,986 --> 01:02:45,166
However, if I had gifs
and jpegs and css,

1447
01:02:45,166 --> 01:02:46,836
it would also go
in this directory.

1448
01:02:47,076 --> 01:02:48,126
But the key point here is

1449
01:02:48,126 --> 01:02:50,616
that there is only
one entry point now

1450
01:02:50,926 --> 01:02:53,546
to my entire site via index.php.

1451
01:02:53,866 --> 01:02:57,086
There is no longer a
lecture0.php, lecture1.php

1452
01:02:57,086 --> 01:02:59,636
in this publicly
accessible directory.

1453
01:02:59,846 --> 01:03:00,686
Well why is that?

1454
01:03:00,686 --> 01:03:04,106
Well let's go ahead
and open up index.php

1455
01:03:04,106 --> 01:03:05,276
and see what it looks like.

1456
01:03:05,556 --> 01:03:09,986
Well in index.php, notice that
we have a bit of complexity,

1457
01:03:10,496 --> 01:03:13,136
but not to syntactically
different

1458
01:03:13,136 --> 01:03:14,326
from what we've done before.

1459
01:03:14,476 --> 01:03:16,606
So first I'm requiring
this helpers file.

1460
01:03:16,876 --> 01:03:19,106
Notice I'm using
a relative path.

1461
01:03:19,106 --> 01:03:22,316
This is a common mistake
when people ship software

1462
01:03:22,566 --> 01:03:24,106
that they've developed
on their own machine.

1463
01:03:24,356 --> 01:03:27,756
Never, ever, ever use hard-coded
paths that start with a slash

1464
01:03:27,756 --> 01:03:29,306
for instance, because
it's just going to break

1465
01:03:29,306 --> 01:03:30,606
when you move it
to another server.

1466
01:03:30,846 --> 01:03:33,096
As best you can, use
relative directories so that

1467
01:03:33,096 --> 01:03:34,326
if you move the whole folder,

1468
01:03:34,326 --> 01:03:35,886
everything works
on another server.

1469
01:03:36,716 --> 01:03:37,716
What am I doing here?

1470
01:03:37,716 --> 01:03:40,646
Well it looks like
I'm going to infer

1471
01:03:40,646 --> 01:03:43,476
from an HTTP parameter
called page,

1472
01:03:43,806 --> 01:03:46,256
which page the user
wants to see.

1473
01:03:46,516 --> 01:03:48,646
So I'm going to store that
in a variable called page,

1474
01:03:48,646 --> 01:03:49,566
and if it's not passed in,

1475
01:03:49,566 --> 01:03:51,716
I'm going to assume
the index so to speak.

1476
01:03:52,016 --> 01:03:54,146
And now I have a switch
statement, which is like an if,

1477
01:03:54,146 --> 01:03:57,086
ltif, ltif, ltif statement,
and how does this work?

1478
01:03:57,236 --> 01:04:02,016
Well, if the page that the user
has requested is the index file,

1479
01:04:02,326 --> 01:04:03,596
go ahead and do the following.

1480
01:04:03,856 --> 01:04:06,706
First render the
header with this title,

1481
01:04:06,916 --> 01:04:09,556
then render the index
with no arguments,

1482
01:04:09,726 --> 01:04:11,256
then render the footer.

1483
01:04:11,356 --> 01:04:13,186
And now notice I'm
using paths here.

1484
01:04:13,186 --> 01:04:14,716
I still left off
the file extension

1485
01:04:14,716 --> 01:04:17,106
because it just looks ugly
to say .php all of the place.

1486
01:04:17,556 --> 01:04:20,966
But I did generalize my render
function as I had before.

1487
01:04:21,306 --> 01:04:23,486
Meanwhile, if I instead
request the lecture...

1488
01:04:23,486 --> 01:04:25,606
Actually, let's skip
down to lectures

1489
01:04:26,036 --> 01:04:28,586
and if I instead request
the lectures pages,

1490
01:04:28,826 --> 01:04:32,266
do something almost the same,
the template for the header,

1491
01:04:32,266 --> 01:04:33,586
render that with this title,

1492
01:04:33,716 --> 01:04:35,926
then render the lectures
template, then,

1493
01:04:35,926 --> 01:04:37,726
rather the lectures view,

1494
01:04:37,906 --> 01:04:42,376
then render the templates/footer
template.

1495
01:04:43,206 --> 01:04:45,726
So now lecture is a
little more interesting.

1496
01:04:46,196 --> 01:04:47,436
It's always kind of bothered me

1497
01:04:47,436 --> 01:04:49,596
that I had a lecture0.php
and a lecture1.php.

1498
01:04:49,596 --> 01:04:53,386
Because even if I'm adhering
to these better practices

1499
01:04:53,586 --> 01:04:55,136
of factoring out the
header and the footer,

1500
01:04:55,456 --> 01:04:58,616
I really wasn't practicing what
I'm preaching with lecture 1

1501
01:04:58,616 --> 01:05:00,266
and lecture 2 and
lecture 3 and lecture 4;

1502
01:05:00,266 --> 01:05:01,176
it feels like I'm
going to get a lot

1503
01:05:01,176 --> 01:05:02,486
of redundancy eventually there.

1504
01:05:02,866 --> 01:05:04,176
So I'm thinking ahead now

1505
01:05:04,406 --> 01:05:06,646
and introducing another
parameter apparently,

1506
01:05:06,696 --> 01:05:07,336
called what?

1507
01:05:07,796 --> 01:05:07,886
Yeah.

1508
01:05:09,276 --> 01:05:10,456
>> Called N.

1509
01:05:10,876 --> 01:05:13,206
>> N. So just a number,
N, presumably,

1510
01:05:13,406 --> 01:05:15,746
so that now my URL's, they
might not look as pretty,

1511
01:05:15,746 --> 01:05:18,236
but we can actually fix
that with modrewrite

1512
01:05:18,236 --> 01:05:19,406
which we look at last time.

1513
01:05:19,696 --> 01:05:20,906
But for now, just assume that,

1514
01:05:20,906 --> 01:05:24,186
there's apparently two
parameters, page and N

1515
01:05:24,186 --> 01:05:28,046
and N is only relevant if
page equals equals lecture.

1516
01:05:28,256 --> 01:05:30,686
But if it is lecture,
then I can do this.

1517
01:05:30,686 --> 01:05:32,976
First render the header
with the title of;

1518
01:05:32,976 --> 01:05:39,256
oh and this interesting, lecture
dot N, but we'll come back

1519
01:05:39,256 --> 01:05:40,256
to this in just a moment.

1520
01:05:40,656 --> 01:05:46,796
And then, lecture N, so render
that template with an input of N

1521
01:05:46,796 --> 01:05:48,416
and then render the footer.

1522
01:05:48,736 --> 01:05:52,156
So let's take a look
now at these views.

1523
01:05:52,496 --> 01:05:55,076
Let me go into the
terminal window again.

1524
01:05:55,536 --> 01:05:58,536
There's nothing else in html, so
I need to go back with dot dot;

1525
01:05:58,926 --> 01:06:03,546
let me go into my view directory
and let me open up my index.

1526
01:06:03,896 --> 01:06:05,736
Well this one is
incredibly uninteresting,

1527
01:06:05,736 --> 01:06:07,196
all it does is have
my main menu.

1528
01:06:07,456 --> 01:06:09,026
But notice what's
not there anymore.

1529
01:06:09,156 --> 01:06:11,206
What redundancy have
I eliminated?

1530
01:06:14,976 --> 01:06:19,806
What used to be in this file?

1531
01:06:19,976 --> 01:06:23,656
Very early on, it had an
html tag, body tag, head tag,

1532
01:06:23,656 --> 01:06:24,696
title tag, all that stuff.

1533
01:06:24,696 --> 01:06:25,326
We ripped that out.

1534
01:06:25,326 --> 01:06:27,646
But what was still left at the
top and bottom of every file?

1535
01:06:27,796 --> 01:06:31,246
>> You still have
things that include

1536
01:06:31,246 --> 01:06:31,486
or run other [inaudible].

1537
01:06:31,486 --> 01:06:31,926
>> Exactly.

1538
01:06:31,926 --> 01:06:35,106
I had the require statements, or
the render statements at the top

1539
01:06:35,156 --> 01:06:36,936
and the bottom of every
one of these files.

1540
01:06:37,176 --> 01:06:38,126
Now that's gone.

1541
01:06:38,126 --> 01:06:39,616
So my views are even simpler.

1542
01:06:39,616 --> 01:06:40,566
So that's the index.

1543
01:06:40,916 --> 01:06:42,356
Well I had a couple other views.

1544
01:06:42,356 --> 01:06:44,866
Let me go ahead and
open up lectures.php.

1545
01:06:44,866 --> 01:06:47,186
That's similarly as simple.

1546
01:06:47,316 --> 01:06:48,236
So that's pretty nice.

1547
01:06:48,576 --> 01:06:50,666
And now let me go
into lecture.php.

1548
01:06:50,666 --> 01:06:52,806
And now this is kind
of interesting

1549
01:06:52,806 --> 01:06:55,036
because not only
is it super short,

1550
01:06:55,366 --> 01:07:01,686
notice that over here what am
I echoing out, N dynamically.

1551
01:07:01,906 --> 01:07:04,596
And so long as I've standardized
the name of my slides,

1552
01:07:04,656 --> 01:07:07,276
the name of my movie file,
video file, and so forth,

1553
01:07:07,406 --> 01:07:09,526
I can generate even
that dynamically.

1554
01:07:10,376 --> 01:07:11,316
But there's a flaw.

1555
01:07:12,386 --> 01:07:13,466
I screwed somewhere.

1556
01:07:15,066 --> 01:07:17,766
What did I forget to do
somewhere in this pipeline?

1557
01:07:22,046 --> 01:07:24,216
There's an excess S
attack here somewhere.

1558
01:07:24,216 --> 01:07:25,936
Which again, we'll come back to
that at the end of the semester,

1559
01:07:25,936 --> 01:07:27,576
but we did talk about
briefly last time.

1560
01:07:28,316 --> 01:07:29,166
And the time before.

1561
01:07:29,256 --> 01:07:29,356
Yeah.

1562
01:07:29,726 --> 01:07:35,946
>> If someone, you didn't
make the [inaudible] are

1563
01:07:35,946 --> 01:07:36,036
safe [inaudible].

1564
01:07:36,036 --> 01:07:36,436
>> Exactly.

1565
01:07:36,436 --> 01:07:37,496
Where did N come from?

1566
01:07:37,496 --> 01:07:39,326
N came from the git string

1567
01:07:39,526 --> 01:07:41,956
and I did not call html
special [inaudible] or anything

1568
01:07:41,956 --> 01:07:45,946
like it either in the previous
file or in this template

1569
01:07:46,256 --> 01:07:48,346
so in short I'm vulnerable
to that same kind

1570
01:07:48,346 --> 01:07:50,056
of stripped attack where
someone might paste

1571
01:07:50,056 --> 01:07:53,376
in some java script code into
my sight without me realizing it

1572
01:07:53,376 --> 01:07:55,686
which can steal my cookies
or other such things.

1573
01:07:55,946 --> 01:07:59,006
So I should minimally be calling
html special [inaudible] here,

1574
01:07:59,296 --> 01:08:01,016
or before even passing it in.

1575
01:08:01,256 --> 01:08:03,516
But frankly my templates are
going to start to look atrocious

1576
01:08:03,516 --> 01:08:05,356
if everywhere I have
html special [inaudible],

1577
01:08:05,356 --> 01:08:06,926
html special [inaudible],
html special [inaudible],

1578
01:08:06,926 --> 01:08:10,906
so another design opportunity
here feels like maybe

1579
01:08:10,906 --> 01:08:13,746
in my render function I
should first be iterating

1580
01:08:13,746 --> 01:08:15,986
over the array, escaping
everything then

1581
01:08:15,986 --> 01:08:18,166
and then passing it
into the template.

1582
01:08:18,166 --> 01:08:19,696
So again another
design opportunity.

1583
01:08:19,696 --> 01:08:22,386
So bearing in mind for
project zero, the axes along

1584
01:08:22,386 --> 01:08:25,346
which we evaluate assignments,
not just scope and correctness

1585
01:08:25,346 --> 01:08:28,286
in style, design is the
more subjective of the four

1586
01:08:28,286 --> 01:08:30,176
and design speaks
to issues like this.

1587
01:08:30,176 --> 01:08:32,306
If you're copying and pasting
the same kind of code again

1588
01:08:32,306 --> 01:08:34,666
and again, you can take
even these lecture examples

1589
01:08:34,666 --> 01:08:38,916
to the next step, the next level
and refine them even further.

1590
01:08:38,916 --> 01:08:44,066
Alright. Let's take a look I
think at one last one here.

1591
01:08:44,586 --> 01:08:50,126
Let me go into seven and
introduce one other trick.

1592
01:08:50,466 --> 01:08:52,516
Or actually, let me
open up version six

1593
01:08:52,516 --> 01:08:57,926
to show you how ugly a
approach it actually was, MVC.

1594
01:08:57,926 --> 01:09:01,656
So let me close Chrome's
inspector.

1595
01:09:02,146 --> 01:09:04,466
Let me go into version
six, html.

1596
01:09:04,546 --> 01:09:06,496
Oh and just to be clear,

1597
01:09:06,686 --> 01:09:09,876
even though I've chmod'd
John Harvard's directory 755

1598
01:09:09,876 --> 01:09:12,056
for the sake of lecture
so we can click around,

1599
01:09:12,396 --> 01:09:14,906
realize that if we actually
take the vhost approach,

1600
01:09:15,126 --> 01:09:17,526
it's the html directory
that could be made

1601
01:09:17,526 --> 01:09:19,996
to be the virtual
host's document root.

1602
01:09:19,996 --> 01:09:21,506
So again, we're just
navigating now

1603
01:09:21,506 --> 01:09:23,196
for convenience in public html.

1604
01:09:23,566 --> 01:09:26,576
So now notice, when I click
on version six's link,

1605
01:09:26,886 --> 01:09:28,216
notice what the URL looks like.

1606
01:09:28,656 --> 01:09:29,986
Page equals lectures.

1607
01:09:30,226 --> 01:09:33,866
That's not all that pretty,
but in worse, when I click

1608
01:09:33,866 --> 01:09:36,076
on lecture zero, then
it really gets ugly.

1609
01:09:36,216 --> 01:09:39,736
Alright. It's not wrong, and
in fact, this is like true use

1610
01:09:39,806 --> 01:09:42,866
of HDP, but frankly this is web
2.0 that we're in now, right.

1611
01:09:42,866 --> 01:09:44,916
And most URL's are
much sexier than this.

1612
01:09:44,916 --> 01:09:46,756
It's just slashes and
words for instance.

1613
01:09:47,026 --> 01:09:50,356
So frankly a sexier
URL than question mark,

1614
01:09:50,356 --> 01:09:52,826
page equals lecture,
ampersand N equals zero,

1615
01:09:53,106 --> 01:09:54,816
would be something
like lecture zero.

1616
01:09:55,186 --> 01:09:57,616
So, something like
just feels cleaner.

1617
01:09:57,616 --> 01:09:59,366
It has not fundamental
difference,

1618
01:09:59,616 --> 01:10:01,196
but it just is the
way things are going

1619
01:10:01,196 --> 01:10:04,806
and various web frameworks
make this easy, easier.

1620
01:10:05,106 --> 01:10:07,086
So, it turns out you
can indeed do this

1621
01:10:07,436 --> 01:10:09,786
with this feature we looked at
last week called modrewrite.

1622
01:10:10,236 --> 01:10:13,716
So now here, let me go ahead
and open up version seven,

1623
01:10:13,806 --> 01:10:19,056
so let me go back to
version seven here, html,

1624
01:10:19,206 --> 01:10:20,676
and let me click on lectures.

1625
01:10:21,116 --> 01:10:24,346
And now this is broken because
I need to add one other thing

1626
01:10:25,216 --> 01:10:29,646
in version seven,
we need this here.

1627
01:10:30,756 --> 01:10:35,836
So, we can actually fake
those prettier URL's

1628
01:10:35,836 --> 01:10:37,636
and still use the
exact same code

1629
01:10:37,636 --> 01:10:39,386
by using this tool
called modrewrite.

1630
01:10:39,386 --> 01:10:44,646
When did we use modrewrite
before, or why?

1631
01:10:44,866 --> 01:10:44,976
Yeah.

1632
01:10:45,516 --> 01:10:47,546
[ Inaudible ]

1633
01:10:48,046 --> 01:10:48,426
As a redirect.

1634
01:10:48,426 --> 01:10:49,616
So that was one such trick.

1635
01:10:49,616 --> 01:10:53,276
And we wanted to redirect from
like hddp to hddps, or we wanted

1636
01:10:53,276 --> 01:10:55,886
to standardize on
www.something.com instead

1637
01:10:55,886 --> 01:10:57,896
of just something.com,
and so forth.

1638
01:10:57,896 --> 01:10:59,446
So anytime you want
to manipulate URL's,

1639
01:10:59,446 --> 01:11:01,016
modrewrite's a powerful tool.

1640
01:11:01,306 --> 01:11:04,556
So here I have an HD
access file that first turns

1641
01:11:04,556 --> 01:11:06,106
on that so-called
rewrite engine.

1642
01:11:06,316 --> 01:11:08,376
I now need a rewrite
base just for the sake

1643
01:11:08,376 --> 01:11:11,286
of these lecture examples
because I'm not in slash,

1644
01:11:11,416 --> 01:11:15,386
because I'm instead in this
silly MVC/7/html directory,

1645
01:11:15,696 --> 01:11:17,516
I need to trick the
server into thinking

1646
01:11:17,516 --> 01:11:20,186
that where I am is the route
directory of the server.

1647
01:11:20,186 --> 01:11:22,426
And that's just again for
lecture purposes here.

1648
01:11:22,426 --> 01:11:24,506
But the last two lines
are generalizable.

1649
01:11:24,776 --> 01:11:26,646
I first have a rewrite
rule that says

1650
01:11:26,646 --> 01:11:30,526
if the user has requested
affectively /lectures,

1651
01:11:30,646 --> 01:11:33,286
and literally just lectures,
the carrot means start

1652
01:11:33,286 --> 01:11:34,356
from the beginning
of the string,

1653
01:11:34,756 --> 01:11:37,626
the dollar sign means match
to the end of the string.

1654
01:11:37,626 --> 01:11:39,426
So if literally the URL
is something, something,

1655
01:11:39,426 --> 01:11:44,586
something/lectures and that's
it, reroute the user's request

1656
01:11:44,936 --> 01:11:47,386
to index.php, question mark,

1657
01:11:47,446 --> 01:11:50,166
page equals lectures,
and that's it.

1658
01:11:50,306 --> 01:11:52,456
So in other words, even
though the user came

1659
01:11:52,456 --> 01:11:55,926
to you via /lectures,
actually respond to them

1660
01:11:55,926 --> 01:11:59,296
as though they went
to this partial URL.

1661
01:11:59,566 --> 01:12:01,396
So this does not
redirect the user.

1662
01:12:01,396 --> 01:12:02,676
Notice there's no R there.

1663
01:12:02,676 --> 01:12:03,676
There's no 301.

1664
01:12:03,676 --> 01:12:04,716
There's no 302.

1665
01:12:04,966 --> 01:12:08,156
This is instead doing a behind
the scenes internal redirect

1666
01:12:08,626 --> 01:12:11,076
because there's no
http there either.

1667
01:12:11,156 --> 01:12:13,926
Because it's a local URL,
the web server does not need

1668
01:12:13,926 --> 01:12:15,946
to redirect the user
with a location header,

1669
01:12:16,066 --> 01:12:19,536
it can do it all inside
the web server itself.

1670
01:12:19,976 --> 01:12:24,516
Meanwhile, if instead the
user visited /lecture/whatever

1671
01:12:24,516 --> 01:12:25,026
this is.

1672
01:12:25,026 --> 01:12:26,166
Now this is just a placeholder.

1673
01:12:26,166 --> 01:12:29,156
Dot means anything, star
means zero or more anythings,

1674
01:12:29,566 --> 01:12:32,216
could then go ahead and redirect
the user to index., sorry,

1675
01:12:32,736 --> 01:12:36,716
then route the user, don't
redirect them, to index.php,

1676
01:12:36,866 --> 01:12:38,796
question mark page
equals lecture

1677
01:12:38,796 --> 01:12:40,566
and N equals dollar sign 1,

1678
01:12:40,566 --> 01:12:42,436
and what does dollar
sign 1 refer to?

1679
01:12:43,586 --> 01:12:43,666
Yeah.

1680
01:12:44,226 --> 01:12:48,366
>> Whatever the [inaudible] you
typed in after the [inaudible].

1681
01:12:48,366 --> 01:12:49,146
>> Exactly.

1682
01:12:49,146 --> 01:12:52,136
Whatever the user typed
in after the lecture/.

1683
01:12:53,016 --> 01:12:54,216
Hopefully, it's numeric.

1684
01:12:54,216 --> 01:12:56,726
Hopefully it's zero
or one or so forth.

1685
01:12:56,856 --> 01:12:59,766
There's nothing stopping the
user typing in fu or bar,

1686
01:12:59,766 --> 01:13:02,666
so lecture/fu, lecture/bar,
in which case,

1687
01:13:02,666 --> 01:13:04,496
they will be passed this page

1688
01:13:04,696 --> 01:13:06,766
where N equals fu
and n equals bar.

1689
01:13:06,996 --> 01:13:09,266
But the once then should
really be on index.php

1690
01:13:09,266 --> 01:13:11,646
to just ignore invalid things.

1691
01:13:11,646 --> 01:13:13,926
We could do some error
checking there to make sure

1692
01:13:14,046 --> 01:13:16,736
that it's only actually a number
so that the site doesn't err.

1693
01:13:16,956 --> 01:13:20,106
Or worst case, we through a 404
and just say file not found,

1694
01:13:20,146 --> 01:13:22,136
which would be reasonable
as well.

1695
01:13:22,526 --> 01:13:25,166
So in short, modrewrite
is incredibly powerful

1696
01:13:25,426 --> 01:13:27,246
and allows you to do
these kinds of tricks,

1697
01:13:27,246 --> 01:13:29,646
and this is very common
with things like Media Wiki,

1698
01:13:29,966 --> 01:13:33,006
with WordPress, Drupel,
all of these various sites

1699
01:13:33,006 --> 01:13:35,456
that you've download and can
run on your own webserver

1700
01:13:35,686 --> 01:13:37,576
to get the sort of pretty URL's

1701
01:13:37,576 --> 01:13:40,446
that the world is now familiar
with, it generally reduces

1702
01:13:40,446 --> 01:13:42,566
to techniques like this.

1703
01:13:42,946 --> 01:13:46,456
Because otherwise /lectures/1
would generally refer

1704
01:13:46,456 --> 01:13:48,306
to like a directory
or something like that

1705
01:13:48,576 --> 01:13:52,046
when it's clearly
not the case here.

1706
01:13:52,046 --> 01:13:53,286
Alright. Any questions?

1707
01:13:53,926 --> 01:13:55,756
Alright. That was a lot.

1708
01:13:55,756 --> 01:13:57,666
Why don't we go ahead and
take a five minute break.

1709
01:13:57,666 --> 01:13:59,426
When we come back,
we'll dive into XML.

1710
01:14:03,666 --> 01:14:04,036
>> Alright.

1711
01:14:04,036 --> 01:14:04,506
We are back.

1712
01:14:04,506 --> 01:14:05,696
So you've met Elan and Peter.

1713
01:14:05,696 --> 01:14:07,576
But I just wanted to
introduce a third member

1714
01:14:07,576 --> 01:14:08,666
of the team who's with us today.

1715
01:14:09,616 --> 01:14:10,876
>> High. I'm Chris Gerber.

1716
01:14:10,876 --> 01:14:12,516
I am of the [inaudible]
teaching fellows.

1717
01:14:12,716 --> 01:14:14,436
I'm an IT manager by day.

1718
01:14:14,436 --> 01:14:17,276
I work on my masters at the
Extension School at night,

1719
01:14:17,516 --> 01:14:19,026
and I'm looking forward
to working with everyone.

1720
01:14:19,626 --> 01:14:20,036
>> Excellent.

1721
01:14:20,036 --> 01:14:20,676
Welcome aboard.

1722
01:14:20,676 --> 01:14:22,576
So Chris will be here
tonight for office hours

1723
01:14:22,576 --> 01:14:24,706
which will be our first
opportunity for one-on-one Q

1724
01:14:24,706 --> 01:14:26,916
and A about material
we've covered thus far,

1725
01:14:26,916 --> 01:14:29,226
about questions you might
have on the spec. If you want

1726
01:14:29,226 --> 01:14:31,826
to take some time either
during or after class to read

1727
01:14:31,826 --> 01:14:33,356
through the PDF that's
already on line.

1728
01:14:33,356 --> 01:14:36,746
But toward the end of lecture
today, we'll also walk in part

1729
01:14:36,746 --> 01:14:38,586
through the specs so that you
have a sense of what awaits

1730
01:14:38,586 --> 01:14:40,116
and what kinds of
questions you might have.

1731
01:14:40,116 --> 01:14:43,036
So definitely take advantage of
these opportunities in person

1732
01:14:43,036 --> 01:14:45,336
for help both in section and
in office hours, and for those

1733
01:14:45,336 --> 01:14:47,976
of you who are distant, as
you saw from Wellie's note,

1734
01:14:47,976 --> 01:14:51,266
one of our own distant TF's will
also be making available some

1735
01:14:51,266 --> 01:14:52,306
opportunities online.

1736
01:14:52,306 --> 01:14:53,936
And even if you're local,
you're welcome to tune

1737
01:14:54,006 --> 01:14:55,636
to those online sessions
as well.

1738
01:14:56,376 --> 01:14:59,136
So that was a whole bunch
on MVC, PHP, Apache.

1739
01:14:59,136 --> 01:15:02,156
Realize that some of
the more mundane minutia

1740
01:15:02,156 --> 01:15:03,356
of like typing the commands

1741
01:15:03,356 --> 01:15:06,126
and what not will be recapped
generally in the spec as needed.

1742
01:15:06,456 --> 01:15:08,256
But any questions?

1743
01:15:08,346 --> 01:15:10,646
Conceptually, mechanically,
or otherwise.

1744
01:15:12,076 --> 01:15:15,776
Otherwise, I'll assume you're
quite comfortable now with git

1745
01:15:15,776 --> 01:15:22,516
and post, and the session
object, and, and MVC.

1746
01:15:22,636 --> 01:15:23,976
Yeah. Okay.

1747
01:15:24,506 --> 01:15:27,136
So let's forge ahead
then into XML,

1748
01:15:27,136 --> 01:15:30,246
which actually has nothing
fundamentally to do with PHP,

1749
01:15:30,316 --> 01:15:33,206
but for which PHP has
wonderful built-in support

1750
01:15:33,266 --> 01:15:35,436
that just makes working
with XML files easy.

1751
01:15:35,436 --> 01:15:38,446
We will see toward the end
of the semester when we look

1752
01:15:38,446 --> 01:15:41,506
at AJAX and JAVA Script,
we'll come full circle to some

1753
01:15:41,506 --> 01:15:43,376
of the same ideas we're
about to discuss here.

1754
01:15:43,376 --> 01:15:45,316
So you'll find that XML
is a topic that comes

1755
01:15:45,316 --> 01:15:46,736
up in all sorts of domains.

1756
01:15:46,736 --> 01:15:50,136
So here is a simple
example of an XML document.

1757
01:15:50,136 --> 01:15:51,976
It kind of looks like
html except again,

1758
01:15:51,976 --> 01:15:53,336
it's sort of make your own tags.

1759
01:15:53,666 --> 01:15:56,366
And in this case, we've made
tags like order, sold to,

1760
01:15:56,366 --> 01:15:58,016
person, last name, first name.

1761
01:15:58,306 --> 01:16:00,726
Everything here happens to
be in upper case; however,

1762
01:16:00,726 --> 01:16:02,576
lowercase is perfectly fine.

1763
01:16:02,576 --> 01:16:05,786
HTML typically should be
all lowercase these days,

1764
01:16:05,786 --> 01:16:08,156
but for XML, you simply
want to be self-consistent.

1765
01:16:08,566 --> 01:16:12,696
So this is apparently some
kind of representation of what?

1766
01:16:16,156 --> 01:16:18,456
This is a computer's way of
representing what, apparently?

1767
01:16:19,076 --> 01:16:21,336
>> Your purchase of
the "Harry Potter

1768
01:16:21,336 --> 01:16:23,466
and the Order of
the Phoenix" book.

1769
01:16:23,466 --> 01:16:23,836
>> Exactly.

1770
01:16:23,836 --> 01:16:25,666
Your purchase of "Harry Potter,"

1771
01:16:25,666 --> 01:16:28,646
which is literally the day I
bought it from Amazon years ago.

1772
01:16:28,996 --> 01:16:30,756
So, what's your name again?

1773
01:16:31,046 --> 01:16:31,476
>> I'm Jack.

1774
01:16:31,666 --> 01:16:32,366
>> Jack. That's right.

1775
01:16:32,366 --> 01:16:33,636
Okay. So as Jack pointed out,

1776
01:16:33,636 --> 01:16:35,446
this represents a
book that was sold.

1777
01:16:35,696 --> 01:16:38,876
So why might this be
relevant in the real world?

1778
01:16:38,876 --> 01:16:41,516
Well, it's not so much a
data format that someone

1779
01:16:41,516 --> 01:16:44,036
like Amazon themselves
would use for storing data

1780
01:16:44,036 --> 01:16:45,076
in their own databases.

1781
01:16:45,126 --> 01:16:47,966
They would need a much faster
performance that you would get

1782
01:16:47,966 --> 01:16:50,446
from something like
MySQUL, or Oracle,

1783
01:16:50,446 --> 01:16:52,656
or a real database engine,
which we'll start looking

1784
01:16:52,656 --> 01:16:53,756
at in a couple of days.

1785
01:16:54,096 --> 01:16:57,506
But for XML, you might
want to; with XML,

1786
01:16:57,676 --> 01:16:58,806
you might very well use it

1787
01:16:58,806 --> 01:17:00,996
to exchange data
between two parties.

1788
01:17:00,996 --> 01:17:03,796
For instance, you might use it
if Amazon has partner-shipped

1789
01:17:04,026 --> 01:17:06,826
with third parties as
they do, to exchange data

1790
01:17:07,016 --> 01:17:09,856
in a non-proprietary,
non-binary format so that

1791
01:17:09,856 --> 01:17:12,906
if that third party has
a database of its own,

1792
01:17:13,066 --> 01:17:15,706
but it's not necessarily
identical or even the same make

1793
01:17:15,706 --> 01:17:21,056
or model as Amazon's, they can
talk in a database neutral way.

1794
01:17:21,056 --> 01:17:24,436
And so XML is actually very
common in the world of RPC,

1795
01:17:24,696 --> 01:17:28,586
remote procedure calls, a topic
generally known as web services,

1796
01:17:28,916 --> 01:17:31,196
or really web-based API's.

1797
01:17:31,196 --> 01:17:33,026
And also common these
days is JSON,

1798
01:17:33,026 --> 01:17:35,186
java script object
notation, which we'll look

1799
01:17:35,186 --> 01:17:37,026
at in a week or two's time.

1800
01:17:37,406 --> 01:17:38,856
So for now, we have some XML.

1801
01:17:39,106 --> 01:17:40,956
Notice a few key features of it.

1802
01:17:40,956 --> 01:17:44,166
One, it's hierarchical,
at least aesthetically.

1803
01:17:44,166 --> 01:17:46,596
Just with html, you don't
need to hit the space bar

1804
01:17:46,596 --> 01:17:48,796
or carriage return or any
of like, anything like that.

1805
01:17:49,036 --> 01:17:50,156
But if you do, you can see

1806
01:17:50,156 --> 01:17:52,186
that there is indeed
a hierarchical nature

1807
01:17:52,186 --> 01:17:52,966
to this document.

1808
01:17:53,286 --> 01:17:57,056
You can see too that we have
some basic building blocks.

1809
01:17:57,056 --> 01:18:00,146
Henceforth, something
like open bracket, order,

1810
01:18:00,146 --> 01:18:02,286
close bracket is what
we'll call an element.

1811
01:18:02,506 --> 01:18:03,546
It's not just a tag.

1812
01:18:03,546 --> 01:18:06,576
An element includes
everything inside

1813
01:18:06,736 --> 01:18:08,786
of that start tag and end tag.

1814
01:18:08,786 --> 01:18:10,416
So the element here is order

1815
01:18:10,646 --> 01:18:12,616
and it has some children
so to speak.

1816
01:18:12,616 --> 01:18:15,426
So sold to is a child
element of order.

1817
01:18:15,486 --> 01:18:18,956
What's another child of
order in this example?

1818
01:18:20,206 --> 01:18:20,686
Yeah. Jack.

1819
01:18:21,136 --> 01:18:21,696
>> Sold on.

1820
01:18:21,786 --> 01:18:22,516
>> Sold on.

1821
01:18:22,726 --> 01:18:25,746
And you can infer it from
the indentation and also

1822
01:18:25,866 --> 01:18:27,566
from the fact that
it's color-coded here.

1823
01:18:27,566 --> 01:18:29,746
But again, if you actually
piece through the open tags

1824
01:18:29,746 --> 01:18:31,806
and closed tags, it is
indeed at the same level

1825
01:18:31,936 --> 01:18:34,136
as sold to, as is item.

1826
01:18:34,136 --> 01:18:37,516
So apparently, element, the
element called order has

1827
01:18:37,516 --> 01:18:40,076
at least three children
that we can see here.

1828
01:18:40,296 --> 01:18:42,176
Now technically,
just as an aside,

1829
01:18:42,656 --> 01:18:45,506
technically order might
have more children,

1830
01:18:46,456 --> 01:18:47,796
even that are pictured here.

1831
01:18:48,096 --> 01:18:51,396
Technically, there is some white
space right after order there,

1832
01:18:51,396 --> 01:18:53,476
there's white space to
the left of sold to,

1833
01:18:53,626 --> 01:18:55,256
so arguably, that's
another child.

1834
01:18:55,256 --> 01:18:56,536
And we'll come back
to this in a bit.

1835
01:18:56,536 --> 01:19:00,286
In XML, when you represent
an XML document in memory,

1836
01:19:00,286 --> 01:19:02,436
with an in-memory data
structure, like a tree,

1837
01:19:02,706 --> 01:19:06,056
it is indeed the case that white
space might matter even though

1838
01:19:06,056 --> 01:19:07,676
fundamentally it
shouldn't matter

1839
01:19:07,676 --> 01:19:08,896
for the data transfer here.

1840
01:19:08,896 --> 01:19:10,066
So more on that in just a bit.

1841
01:19:10,606 --> 01:19:13,136
So, "sold to" has a
child called "person."

1842
01:19:13,136 --> 01:19:15,586
Person has two children called
"last name" and "first name."

1843
01:19:15,866 --> 01:19:18,846
But person has something else,
just like html, an attribute

1844
01:19:18,846 --> 01:19:21,856
with a value in this case,
which should be quoted just

1845
01:19:21,856 --> 01:19:23,906
as I've done here, single
or double quotes are fine,

1846
01:19:23,906 --> 01:19:25,216
so long as you are consistent.

1847
01:19:25,476 --> 01:19:28,446
And then elements can have
zero or more attributes,

1848
01:19:28,446 --> 01:19:31,296
but those attributes
must be uniquely named.

1849
01:19:31,296 --> 01:19:33,176
You can't have two
ID attributes.

1850
01:19:33,586 --> 01:19:36,766
So very quickly we're going
to run into a question here

1851
01:19:36,766 --> 01:19:39,186
of attributes versus children.

1852
01:19:40,116 --> 01:19:43,546
When or why should
you make a piece

1853
01:19:43,546 --> 01:19:47,926
of data an attribute do you
think versus a child element?

1854
01:19:49,076 --> 01:19:51,666
And again, we've only done a
quick definition of XML here,

1855
01:19:51,666 --> 01:19:53,376
but you've been using
attributes and elements

1856
01:19:53,376 --> 01:19:54,536
in HTML for some time.

1857
01:19:54,636 --> 01:19:54,736
Yeah.

1858
01:19:55,706 --> 01:20:00,406
>> When they're related or
unrelated to the other elements.

1859
01:20:00,406 --> 01:20:02,076
>> Okay. So when they're
related or unrelated

1860
01:20:02,076 --> 01:20:02,856
to the other elements.

1861
01:20:02,856 --> 01:20:04,786
So in this case,
ID is an attribute

1862
01:20:04,786 --> 01:20:06,496
because it doesn't really
have something to do

1863
01:20:06,496 --> 01:20:07,806
with first name and last name.

1864
01:20:07,806 --> 01:20:08,656
And that's reasonable.

1865
01:20:08,656 --> 01:20:10,586
It's sort of conceptually
distinct.

1866
01:20:11,196 --> 01:20:11,936
So that's reasonable.

1867
01:20:11,936 --> 01:20:15,266
What else might motivate making
ID an attribute as we have here

1868
01:20:15,586 --> 01:20:16,946
as opposed to a child element?

1869
01:20:18,116 --> 01:20:19,856
And by, to be clear, I mean what

1870
01:20:19,856 --> 01:20:22,926
if instead I had not written ID
equals quote unquote one, two,

1871
01:20:22,926 --> 01:20:26,116
three, instead after the
close brace, I'd hit enter,

1872
01:20:26,116 --> 01:20:29,396
and then done open bracket, ID,
close bracket, one, two, three,

1873
01:20:29,396 --> 01:20:32,706
open bracket, slash
ID, close bracket.

1874
01:20:32,826 --> 01:20:33,906
So all I mean by a child owned.

1875
01:20:34,156 --> 01:20:37,136
>> Sorry. I should have
been more specific.

1876
01:20:37,136 --> 01:20:38,356
When it's sort of
immutable data,

1877
01:20:38,356 --> 01:20:40,846
it goes along with that child.

1878
01:20:40,846 --> 01:20:41,316
>> Aw. Good.

1879
01:20:41,316 --> 01:20:43,986
So a little different there;
so when the data is immutable,

1880
01:20:44,216 --> 01:20:46,516
and really a leaf of sorts,

1881
01:20:46,516 --> 01:20:50,136
where it itself cannot have any
notion conceptually of children.

1882
01:20:50,136 --> 01:20:52,906
So when you are an identifier
like a number, a one, two,

1883
01:20:52,906 --> 01:20:55,466
three, we're never going to
be able to tease that apart

1884
01:20:55,466 --> 01:20:57,976
in the same way that you
could tease out a person

1885
01:20:57,976 --> 01:21:01,026
into a first name and a last
name, maybe even a middle name.

1886
01:21:01,276 --> 01:21:03,386
So there's some notion of
hierarchy there potentially.

1887
01:21:03,386 --> 01:21:05,156
But in ID, that's it.

1888
01:21:05,156 --> 01:21:08,066
When are you ever going to tease
an ID apart into something more

1889
01:21:08,066 --> 01:21:09,346
if it's just a number
to begin with?

1890
01:21:09,646 --> 01:21:10,976
So in that sense,
very reasonable

1891
01:21:11,076 --> 01:21:12,806
to make ID an attribute
because you don't need

1892
01:21:12,806 --> 01:21:16,156
to extend its definition
later, and indeed that's

1893
01:21:16,156 --> 01:21:17,406
where the X in XML comes from.

1894
01:21:17,406 --> 01:21:20,506
It's extensible markup
language and that really speaks

1895
01:21:20,536 --> 01:21:23,186
to the ability to
[inaudible] and explode it

1896
01:21:23,186 --> 01:21:26,776
into more semantic detail by
adding more and more tags just

1897
01:21:26,776 --> 01:21:29,586
so that you can markup
more pieces of data.

1898
01:21:29,586 --> 01:21:33,316
In fact, why did I use last
name and first name instead

1899
01:21:33,316 --> 01:21:36,426
of just name, which seems
also pretty reasonable?

1900
01:21:37,866 --> 01:21:39,546
Why have last name
and first name here?

1901
01:21:42,056 --> 01:21:42,123
Yeah.

1902
01:21:42,276 --> 01:21:49,156
>> In case you want
to, I don't know

1903
01:21:49,436 --> 01:21:52,596
like use the more specific
information when you're

1904
01:21:52,596 --> 01:21:54,186
like sorting by last name.

1905
01:21:54,346 --> 01:21:54,616
>> Okay. Good.

1906
01:21:54,616 --> 01:21:58,916
Maybe we want to use that
more specific information

1907
01:21:59,036 --> 01:22:02,166
like sorting by last name,
sorting by first name,

1908
01:22:02,166 --> 01:22:03,846
or even simple customizations.

1909
01:22:04,056 --> 01:22:08,466
When you get those form
letters from companies,

1910
01:22:08,686 --> 01:22:11,986
Dear David Mayland, feels
very cold and I realize

1911
01:22:12,076 --> 01:22:16,186
that it's still a machine doing
it when it says just Dear David,

1912
01:22:16,186 --> 01:22:19,696
but at least it's a little more
human like, and it's harder

1913
01:22:19,696 --> 01:22:23,346
to do that if you just
had a name attribute

1914
01:22:23,586 --> 01:22:27,196
because there are
certainly people out there

1915
01:22:27,196 --> 01:22:31,536
who don't just have first
names and last names,

1916
01:22:31,686 --> 01:22:34,416
there's middle names,
there's two middle names,

1917
01:22:34,586 --> 01:22:35,816
three middle names.

1918
01:22:35,816 --> 01:22:38,646
It's not clear necessarily
where the break is

1919
01:22:38,646 --> 01:22:44,376
between someone's given name and
their family name for instance.

1920
01:22:44,376 --> 01:22:48,166
So doing it in this
way helps with that.

1921
01:22:48,166 --> 01:22:51,616
Alright. So what else is
interesting about this?

1922
01:22:51,786 --> 01:22:55,956
We have tags as are, in present
in html, end tags and the like.

1923
01:22:55,956 --> 01:22:57,176
We have some text.

1924
01:22:57,286 --> 01:23:00,936
So hopefully syntactically
this is all pretty familiar.

1925
01:23:00,936 --> 01:23:01,386
And it's nice.

1926
01:23:01,386 --> 01:23:07,436
It's a little freeing in that
we can now use our own tags.

1927
01:23:07,436 --> 01:23:11,596
But here's what I mean
about the X, extensibility.

1928
01:23:11,856 --> 01:23:15,926
Suppose in the future we
decided, you know what,

1929
01:23:15,926 --> 01:23:20,676
we want to go ahead and add a
bit more detail to a person.

1930
01:23:20,956 --> 01:23:24,256
So notice I still have person,
and last name and first name.

1931
01:23:24,626 --> 01:23:27,336
But I've decided to
introduce the initial,

1932
01:23:27,336 --> 01:23:29,406
J in my case for this person.

1933
01:23:29,406 --> 01:23:32,436
And I also want to
insert their address.

1934
01:23:32,436 --> 01:23:33,426
What's compelling here is

1935
01:23:33,426 --> 01:23:36,756
that even though the XML
document has grown in size,

1936
01:23:36,756 --> 01:23:40,166
I have not broken the
structure of anything

1937
01:23:40,466 --> 01:23:41,826
that was there before.

1938
01:23:41,826 --> 01:23:45,826
So XML is compelling in that
if this is something being used

1939
01:23:45,826 --> 01:23:48,816
by Amazon and some random
third-party partner of theirs,

1940
01:23:48,816 --> 01:23:51,346
in theory, if you've
written your software well,

1941
01:23:51,406 --> 01:23:55,266
whereby you expect that XML
documents might have more

1942
01:23:55,266 --> 01:23:57,586
elements than you care
about, but not necessarily

1943
01:23:57,586 --> 01:23:59,906
in such a way that
they'll break the document.

1944
01:23:59,906 --> 01:24:03,316
Hopefully, if Amazon tomorrow
decides you know what we're

1945
01:24:03,406 --> 01:24:07,466
going to start giving our third
parties middle initials as well

1946
01:24:07,466 --> 01:24:08,856
as people's addresses,

1947
01:24:08,856 --> 01:24:11,876
which frankly they should
have done the first time,

1948
01:24:12,036 --> 01:24:15,246
that hopefully won't
break any code

1949
01:24:15,246 --> 01:24:17,706
that other people have
written to ingest this XML.

1950
01:24:17,706 --> 01:24:22,976
It, worst case, it will
be ignored, the initial,

1951
01:24:22,976 --> 01:24:26,056
and the address, but at least
it won't break any existing

1952
01:24:26,056 --> 01:24:32,696
workflow and that's one of the
salient characteristics of XML.

1953
01:24:33,236 --> 01:24:36,126
Well, let's take
another example here.

1954
01:24:36,126 --> 01:24:39,996
So how about a student's
database of sorts?

1955
01:24:40,106 --> 01:24:44,196
Again, not good for long
term storage of lots and lots

1956
01:24:44,196 --> 01:24:49,686
and students, but for something
short like a pizzeria menu,

1957
01:24:49,686 --> 01:24:51,506
something like XML
might suffice,

1958
01:24:51,506 --> 01:24:53,806
or even a small database
of students.

1959
01:24:53,806 --> 01:24:56,956
So what characteristics
do we have here?

1960
01:24:56,956 --> 01:24:59,256
We have even more
features in this document,

1961
01:24:59,256 --> 01:25:00,946
which is what it's
meant to convey.

1962
01:25:00,946 --> 01:25:03,146
So at the top here is the
so-called XML declaration.

1963
01:25:03,146 --> 01:25:04,896
Very tragically, this
looks a little bit like...

1964
01:25:04,896 --> 01:25:04,963
>> PHP.

1965
01:25:04,963 --> 01:25:07,006
>> PHP because of the dang
open bracket question mark.

1966
01:25:07,036 --> 01:25:08,236
So whereas you can include
HTML in PHP files raw

1967
01:25:08,266 --> 01:25:08,836
and have them spit out,

1968
01:25:08,866 --> 01:25:10,186
you cannot include an XML
declaration in PHP files

1969
01:25:10,216 --> 01:25:10,936
because it will be confused

1970
01:25:10,966 --> 01:25:12,016
by the PHP interpreter
as being a PHP tag.

1971
01:25:12,046 --> 01:25:13,786
So instead you have to resort to
a hack like using echo or print

1972
01:25:13,816 --> 01:25:14,536
for this one feature of XML.

1973
01:25:14,566 --> 01:25:15,556
But just realize
there's that corner case.

1974
01:25:15,586 --> 01:25:16,906
Technically though, the SML
declaration is not required.

1975
01:25:16,936 --> 01:25:17,956
It's simply optional,
but it says things

1976
01:25:17,986 --> 01:25:19,486
like what encoding have you
used in terms of character set?

1977
01:25:19,516 --> 01:25:20,506
And what version of
XML are you using?

1978
01:25:20,536 --> 01:25:20,956
In this case, one.

1979
01:25:20,986 --> 01:25:21,586
So, now we have this thing.

1980
01:25:21,616 --> 01:25:22,336
This is obviously a comment.

1981
01:25:22,366 --> 01:25:23,926
This is part of the XML spec.
You can have comments in it.

1982
01:25:23,956 --> 01:25:25,186
And in fact when you
build up a tree in memory,

1983
01:25:25,216 --> 01:25:26,476
you wouldn't do this yourself,
a browser would do this

1984
01:25:26,506 --> 01:25:27,466
or a parser would do
this on the server.

1985
01:25:27,496 --> 01:25:28,126
When you build up the tree

1986
01:25:28,156 --> 01:25:29,326
that represents this
hierarchical document,

1987
01:25:29,356 --> 01:25:30,676
you will get nodes in that
tree represent comments.

1988
01:25:30,706 --> 01:25:32,146
So they're not, they're ignored
typically in terms of rendering.

1989
01:25:32,176 --> 01:25:33,526
You don't see HTML comments
in a page, but they are there

1990
01:25:33,556 --> 01:25:34,756
and they are stored in
RAM as a node in a tree.

1991
01:25:34,786 --> 01:25:36,346
So this thing is the so-called
root element of the document.

1992
01:25:36,376 --> 01:25:37,876
An XML document like an
HTML document can have one

1993
01:25:37,906 --> 01:25:38,626
and only one root element.

1994
01:25:38,656 --> 01:25:39,976
In the world of HTML, what
is the root element called?

1995
01:25:43,406 --> 01:25:44,456
HTML, right.

1996
01:25:44,456 --> 01:25:47,606
In the world of XML it can be
called anything you want so long

1997
01:25:47,606 --> 01:25:50,486
as there's one and only
one element at that level.

1998
01:25:50,486 --> 01:25:52,106
If you want to put
something else at that level,

1999
01:25:52,106 --> 01:25:54,016
it frankly has to be
in another XML file.

2000
01:25:54,016 --> 01:25:55,396
That's simply the
way the spec works.

2001
01:25:55,936 --> 01:25:57,876
So student is a child
of students.

2002
01:25:57,876 --> 01:25:59,956
It has an ID in this
case of 001.

2003
01:26:00,336 --> 01:26:01,916
Their name here is Jim Bob.

2004
01:26:01,916 --> 01:26:03,086
Status, a graduate.

2005
01:26:03,086 --> 01:26:04,556
Dorm, this looks a little weird.

2006
01:26:05,566 --> 01:26:07,086
What does this resemble?

2007
01:26:07,136 --> 01:26:08,516
And what does this
mean do you think?

2008
01:26:08,886 --> 01:26:08,976
Jack.

2009
01:26:09,516 --> 01:26:15,546
[ Inaudible ]

2010
01:26:16,046 --> 01:26:16,246
Okay. Good.

2011
01:26:16,246 --> 01:26:18,766
So it's a tag that's opened
and closed all at once

2012
01:26:18,836 --> 01:26:21,176
and that typically
implies that it's empty.

2013
01:26:21,216 --> 01:26:23,686
The element can be there
but there's no data for it,

2014
01:26:23,686 --> 01:26:26,086
so it's an empty element
and here it makes sense

2015
01:26:26,126 --> 01:26:28,066
that this student
might not have a dorm

2016
01:26:28,066 --> 01:26:29,736
because she's a graduate
student,

2017
01:26:29,736 --> 01:26:30,716
so there's just no address.

2018
01:26:31,096 --> 01:26:33,386
So maybe this could be removed
altogether, but the fact

2019
01:26:33,386 --> 01:26:35,476
that it's there is not
necessarily a bad thing.

2020
01:26:35,476 --> 01:26:37,486
In fact, the receiving
party might prefer that it

2021
01:26:37,486 --> 01:26:40,426
at least be there to make ever
so clear that there is no dorm,

2022
01:26:40,506 --> 01:26:42,696
not that we forgot
to include the dorm.

2023
01:26:42,906 --> 01:26:48,096
This might resemble an HR tag,
BR tag, HTML has empty elements

2024
01:26:48,416 --> 01:26:50,986
that even though in HTML
you don't have to close them

2025
01:26:50,986 --> 01:26:53,546
with a slash, if you're
familiar with XHTML,

2026
01:26:53,546 --> 01:26:55,996
which is an XML compliant
version of HTML

2027
01:26:56,256 --> 01:26:59,016
where all tags must
be open and closed,

2028
01:26:59,156 --> 01:27:03,586
attribute values must be quoted,
and all tags must be closed even

2029
01:27:03,586 --> 01:27:04,546
if they're empty like this.

2030
01:27:05,186 --> 01:27:06,606
Might have seen this
syntax before.

2031
01:27:06,926 --> 01:27:08,176
Okay. Now we have a major.

2032
01:27:08,376 --> 01:27:09,506
And here's a curious thing.

2033
01:27:09,506 --> 01:27:14,986
Why is my major, is Jim Bob's
major computer science ampersand

2034
01:27:14,986 --> 01:27:17,016
amp semicolon music?

2035
01:27:18,206 --> 01:27:21,606
And what does this
remind you of?

2036
01:27:27,126 --> 01:27:27,826
Yeah. Isaac.

2037
01:27:27,826 --> 01:27:28,496
>> Double major.

2038
01:27:29,206 --> 01:27:31,636
>> Okay. It does
imply a double major.

2039
01:27:31,886 --> 01:27:34,396
But what's with this cryptic
thing that's never going to show

2040
01:27:34,396 --> 01:27:37,196
up on our Harvard diploma,
ampersand amp semicolon?

2041
01:27:38,036 --> 01:27:38,916
What is that all about?

2042
01:27:38,916 --> 01:27:38,983
Yeah.

2043
01:27:39,516 --> 01:27:41,826
[ Inaudible ]

2044
01:27:42,326 --> 01:27:42,676
The next...

2045
01:27:42,826 --> 01:27:45,026
Not next line, actually.

2046
01:27:45,176 --> 01:27:46,496
Not a bad guess, though.

2047
01:27:47,516 --> 01:27:52,826
[ Inaudible ]

2048
01:27:53,326 --> 01:27:57,916
Exactly. So this is an
HTML, this is an XML entity

2049
01:27:58,266 --> 01:28:02,346
which is present here because
ampersand is a special character

2050
01:28:02,346 --> 01:28:03,376
in XML.

2051
01:28:03,656 --> 01:28:05,576
It demarks the start
of an entity

2052
01:28:05,576 --> 01:28:08,116
and you've probably seen an HTML
[inaudible] at least one entity.

2053
01:28:08,366 --> 01:28:10,506
Ampersand NBSP semicolon,

2054
01:28:10,506 --> 01:28:13,246
non-breaking space,
is one special one.

2055
01:28:13,286 --> 01:28:17,146
In XML, actually there's other
in HML, ampersand GT for greater

2056
01:28:17,146 --> 01:28:19,516
than semicolon, ampersand
LT less

2057
01:28:19,576 --> 01:28:21,286
than followed by a semicolon.

2058
01:28:21,436 --> 01:28:25,036
There's some special characters
in HTML and XML called entities

2059
01:28:25,036 --> 01:28:27,896
that always start with semi,
always start with ampersands

2060
01:28:28,276 --> 01:28:31,026
and always end with
semicolons and the word

2061
01:28:31,026 --> 01:28:32,376
between is some identifier.

2062
01:28:32,376 --> 01:28:34,186
AMP here means ampersand.

2063
01:28:34,456 --> 01:28:36,556
So, even though it's
a little coincidental

2064
01:28:36,556 --> 01:28:38,356
that there's an ampersand
followed by AMP,

2065
01:28:38,356 --> 01:28:43,246
this means that this is an HTML
entity representing a single

2066
01:28:43,246 --> 01:28:46,286
ampersand which represents
the word and.

2067
01:28:46,776 --> 01:28:51,596
Similarly, if we wanted to put
a less than character as part

2068
01:28:51,596 --> 01:28:54,636
of my major for whatever weird
crazy reason, I would need

2069
01:28:54,636 --> 01:28:57,866
to do ampersand LT semicolon.

2070
01:28:57,966 --> 01:29:03,906
So, in short, in XML documents,
if you have raw ampersands

2071
01:29:03,906 --> 01:29:06,986
in your document, you must
escape them in this way here.

2072
01:29:07,956 --> 01:29:09,226
Okay. What else is
interesting here?

2073
01:29:09,226 --> 01:29:11,446
See data. We'll come
back to that.

2074
01:29:11,446 --> 01:29:14,006
We've got some H1 in here;
we've got another student idea.

2075
01:29:14,196 --> 01:29:18,586
So let's tease these apart
a little more specifically.

2076
01:29:18,586 --> 01:29:20,726
So I'll fly through some
of these things just

2077
01:29:20,726 --> 01:29:23,076
because they're kind of
mind-numbing details,

2078
01:29:23,076 --> 01:29:24,526
but more formal definitions

2079
01:29:24,526 --> 01:29:26,316
of these various
pieces of XML files.

2080
01:29:26,616 --> 01:29:28,406
So the XML declaration reminded

2081
01:29:28,406 --> 01:29:32,536
at top right there represents
again an optional piece of data

2082
01:29:32,886 --> 01:29:35,106
that essentially informs
whatever program's reading the

2083
01:29:35,106 --> 01:29:36,796
XML document what
version you're using,

2084
01:29:36,796 --> 01:29:38,486
what encoding, and the like.

2085
01:29:38,976 --> 01:29:41,846
So elements, we talked about
in the context of the example.

2086
01:29:41,846 --> 01:29:43,016
But there are a few rules.

2087
01:29:43,016 --> 01:29:45,496
So one, they always need a
start tag and an end tag.

2088
01:29:45,896 --> 01:29:47,506
If the start tag has attributes,

2089
01:29:47,506 --> 01:29:49,746
the end tag does
not have attributes.

2090
01:29:50,056 --> 01:29:51,066
Just like the HTML.

2091
01:29:51,336 --> 01:29:53,576
There are some constraints on
names which you should bear

2092
01:29:53,576 --> 01:29:55,906
in mind for pizza
ML, for project zero.

2093
01:29:55,906 --> 01:29:58,646
They have to start with a
letter or an underscore.

2094
01:29:58,886 --> 01:30:01,006
They cannot start with
numbers which is one

2095
01:30:01,006 --> 01:30:03,336
of the minor annoyances
with XML,

2096
01:30:03,576 --> 01:30:06,356
but they can have a few other
characters in them as well.

2097
01:30:06,356 --> 01:30:08,146
And again so that you don't have
to scribble everything down,

2098
01:30:08,496 --> 01:30:10,846
these slides are on the
course's website as always.

2099
01:30:11,276 --> 01:30:12,346
So content model.

2100
01:30:12,346 --> 01:30:13,966
So this is something
worth keeping in mind

2101
01:30:13,966 --> 01:30:15,226
because it again
allows you to sort

2102
01:30:15,226 --> 01:30:17,656
of model different
design decisions.

2103
01:30:18,946 --> 01:30:20,116
If you have an element,

2104
01:30:20,376 --> 01:30:23,766
an element can have
different stuff inside of it,

2105
01:30:23,886 --> 01:30:25,286
that is nested inside of it.

2106
01:30:25,576 --> 01:30:27,866
In the first case, you
might have element content,

2107
01:30:27,866 --> 01:30:30,936
whereby you have an element
like student and then inside

2108
01:30:30,936 --> 01:30:32,416
of which is another element,

2109
01:30:32,466 --> 01:30:34,476
in this case called
status, and then that's it.

2110
01:30:34,686 --> 01:30:36,266
So this is so-called
element content.

2111
01:30:36,766 --> 01:30:39,106
You might have PC data,
parsed character data,

2112
01:30:39,106 --> 01:30:41,466
so Jim Bob that was an
example from before too,

2113
01:30:41,736 --> 01:30:45,956
the child of name in this
case is a, is PC data,

2114
01:30:46,116 --> 01:30:47,156
parsed character data.

2115
01:30:47,516 --> 01:30:48,306
What does that mean?

2116
01:30:48,306 --> 01:30:50,486
Well, we'll come back
to that in a moment.

2117
01:30:50,486 --> 01:30:52,596
But for now, just
assume it means text.

2118
01:30:53,226 --> 01:30:54,306
How about mixed content?

2119
01:30:54,306 --> 01:30:56,446
This is kind of a weird
example that you should not do

2120
01:30:56,446 --> 01:30:58,306
in practice, but it
does convey the idea.

2121
01:30:58,706 --> 01:31:00,896
You have a name element,
and then you have Jim Bob,

2122
01:31:00,896 --> 01:31:03,036
but Jim Bob this time has
an initial and we wanted

2123
01:31:03,036 --> 01:31:05,176
to semantically tag his
middle name for some reason,

2124
01:31:05,176 --> 01:31:06,336
but not his first or last name.

2125
01:31:06,336 --> 01:31:08,616
So again, bad design,
but it does hint

2126
01:31:08,616 --> 01:31:13,826
at how you can technically
comingle PC data with elements.

2127
01:31:13,826 --> 01:31:15,376
So this is a mixed content model

2128
01:31:15,376 --> 01:31:16,566
because you don't
just have text,

2129
01:31:17,116 --> 01:31:20,326
you don't just have an element,
you have both intermingled.

2130
01:31:20,876 --> 01:31:23,206
This is more real if you
think about HTML now.

2131
01:31:23,586 --> 01:31:26,106
In HTML it's very common
to have a paragraph tag

2132
01:31:26,106 --> 01:31:27,706
and then you start
writing your paragraph.

2133
01:31:27,706 --> 01:31:28,946
But then in the middle
of your paragraph,

2134
01:31:28,946 --> 01:31:31,666
you enter the boldface
tag or the italics tag

2135
01:31:31,796 --> 01:31:33,016
and then you close that tag,

2136
01:31:33,316 --> 01:31:35,146
that too would be a
mixed content model.

2137
01:31:35,146 --> 01:31:37,646
You have text and
tags comingled.

2138
01:31:37,976 --> 01:31:40,276
Then no content, like dorm,
like Jack pointed out.

2139
01:31:40,576 --> 01:31:42,406
So we have those
several content models.

2140
01:31:42,596 --> 01:31:43,956
Those are our options
for modeling.

2141
01:31:44,276 --> 01:31:45,296
Attributes again.

2142
01:31:45,296 --> 01:31:46,196
Pretty straight forward.

2143
01:31:46,196 --> 01:31:47,506
Very reminiscent of HTML.

2144
01:31:47,506 --> 01:31:48,996
Must start with letter
or underscore

2145
01:31:48,996 --> 01:31:51,536
and only contain
letters and so forth.

2146
01:31:51,536 --> 01:31:54,206
They must be quoted
here in this case.

2147
01:31:54,206 --> 01:31:57,766
HTML is not as, not as
rigorous about this.

2148
01:31:57,766 --> 01:32:00,316
HTML Five at least, but
XML still expects you

2149
01:32:00,316 --> 01:32:03,036
to quote things either with
single quotes or double quotes

2150
01:32:03,136 --> 01:32:06,006
and then again this last
bullet is the most scary,

2151
01:32:06,006 --> 01:32:10,046
you cannot have ampersands
or less than characters.

2152
01:32:10,046 --> 01:32:12,056
You must escape those
with entities.

2153
01:32:12,866 --> 01:32:14,836
Alright PC Data just
represents text.

2154
01:32:14,836 --> 01:32:16,456
So let's fly by this.

2155
01:32:17,006 --> 01:32:17,996
And now entities.

2156
01:32:18,056 --> 01:32:20,116
So now we see a more
formal definition here.

2157
01:32:20,306 --> 01:32:22,326
So there again, used
to escape characters

2158
01:32:22,326 --> 01:32:25,576
that might otherwise cause
breakages in XML files.

2159
01:32:25,896 --> 01:32:29,296
In XML you get five entities
for free, ampersand, less than,

2160
01:32:29,296 --> 01:32:32,506
greater than, apostrophe, and
double quotes, and that's it,

2161
01:32:32,506 --> 01:32:33,816
only those five exist.

2162
01:32:34,256 --> 01:32:36,106
In fact, MBSP is
not on the list.

2163
01:32:36,296 --> 01:32:38,066
So if you want something
like that you have

2164
01:32:38,066 --> 01:32:41,666
to define it yourself and you
will not likely need to do this

2165
01:32:41,666 --> 01:32:43,946
for this project unless you
really want to get fancy.

2166
01:32:44,206 --> 01:32:46,556
This is the syntax
in an XML file

2167
01:32:46,896 --> 01:32:49,426
for how you can declare
your own entities.

2168
01:32:49,736 --> 01:32:53,576
So in the world of HTML, someone
somewhere wrote out this entity

2169
01:32:53,706 --> 01:32:57,236
for non-breaking space and
what does 160 likely refer to?

2170
01:32:58,336 --> 01:32:58,976
Where does that come from?

2171
01:33:04,046 --> 01:33:06,016
So it that's a decimal
number, 160,

2172
01:33:06,116 --> 01:33:08,126
and that is simply
the numeric code

2173
01:33:08,126 --> 01:33:12,466
that represents the character
we know as a non-breaking space.

2174
01:33:12,466 --> 01:33:14,026
It's not something you
can type on the keyboard,

2175
01:33:14,396 --> 01:33:16,216
but rather that's
its numeric code,

2176
01:33:16,216 --> 01:33:17,836
so it's uniquely identifiable.

2177
01:33:18,446 --> 01:33:19,056
Alright, any questions?

2178
01:33:19,056 --> 01:33:24,376
And actually you've seen
HTML entities before, right.

2179
01:33:24,376 --> 01:33:25,336
If you've ever looked
up something

2180
01:33:25,336 --> 01:33:29,756
like a copyright symbol or
a weird triangle or circle

2181
01:33:30,076 --> 01:33:34,076
or some symbol to use in a web
page, you've probably used one

2182
01:33:34,076 --> 01:33:36,086
of these entities,
albeit in HTML.

2183
01:33:36,486 --> 01:33:38,006
So character data's
a little different.

2184
01:33:38,006 --> 01:33:40,776
Recall we had this snippet at
the top right here for C data.

2185
01:33:41,446 --> 01:33:45,836
This will rarely, this will
not always be necessary.

2186
01:33:46,136 --> 01:33:47,306
But sometimes is.

2187
01:33:47,686 --> 01:33:54,546
If you want to have raw HTML or
JAVA script or any piece of data

2188
01:33:54,906 --> 01:33:57,626
that might have scary
characters like open brackets

2189
01:33:57,736 --> 01:34:01,006
and ampersands that it just
doesn't make sense to escape.

2190
01:34:01,336 --> 01:34:03,706
For instance, suppose you
wanted for whatever reason,

2191
01:34:03,836 --> 01:34:07,376
to store JAVA script
inside of an XML file.

2192
01:34:07,656 --> 01:34:09,686
It's not unreasonable
to store a piece of data

2193
01:34:09,686 --> 01:34:10,836
in another piece of data.

2194
01:34:11,166 --> 01:34:14,256
But JAVA script has
arithmetic functions and things

2195
01:34:14,256 --> 01:34:16,016
like less thans and
greater thans.

2196
01:34:16,446 --> 01:34:18,806
Right. It would be kind
of ridiculous if you had

2197
01:34:18,806 --> 01:34:22,476
to rewrite your JAVA script
code to ask, to change things

2198
01:34:22,476 --> 01:34:24,756
like if X is less
than Y, then do this.

2199
01:34:25,126 --> 01:34:26,196
If you had to rewrite that as

2200
01:34:26,196 --> 01:34:31,066
if X is ampersand LT
semicolon Y, right.

2201
01:34:31,066 --> 01:34:32,646
That's not JAVA script.

2202
01:34:32,646 --> 01:34:35,666
That's a weird amalgam
of XML and JAVA script.

2203
01:34:35,946 --> 01:34:38,606
So C data exists for
instance for that purpose

2204
01:34:38,776 --> 01:34:41,066
where you can tell
an XML parser,

2205
01:34:41,066 --> 01:34:42,636
a program that reads
an XML file,

2206
01:34:42,636 --> 01:34:44,176
much like you yourselves
will write.

2207
01:34:44,516 --> 01:34:47,856
You can say ignore the following
stuff, do not parse it.

2208
01:34:47,856 --> 01:34:52,056
It's C data, character data, not
parsed character data, PC data.

2209
01:34:52,376 --> 01:34:53,946
And you can just
say to the parser,

2210
01:34:54,216 --> 01:34:57,666
just suck in everything you're
about to see without worrying

2211
01:34:57,666 --> 01:35:01,716
about its syntactic validity,
I'll worry about that.

2212
01:35:01,716 --> 01:35:04,026
So in this case, I'm using
it, not for JAVA script.

2213
01:35:04,146 --> 01:35:06,986
But if you want to store
HTML in an XML file,

2214
01:35:07,206 --> 01:35:09,486
you don't want your HTML
tags to be conflated

2215
01:35:09,486 --> 01:35:11,896
as XML tags, which
they could be.

2216
01:35:11,896 --> 01:35:13,626
Because again, XML you
make your own tags.

2217
01:35:13,936 --> 01:35:15,806
Just because they're HTML
doesn't mean you can't use the

2218
01:35:15,806 --> 01:35:17,206
same names for your tags.

2219
01:35:17,606 --> 01:35:21,146
So if you wanted to include
some HTML in an XML document,

2220
01:35:21,516 --> 01:35:24,596
you have to unfortunately
wrap the characters

2221
01:35:24,596 --> 01:35:28,196
with open bracket bang open
bracket C data, open bracket,

2222
01:35:28,196 --> 01:35:30,146
and then at the end,
close bracket,

2223
01:35:30,146 --> 01:35:31,816
close bracket, close
angled bracket.

2224
01:35:32,246 --> 01:35:33,926
Now why in the world did
they choose those sequence

2225
01:35:33,926 --> 01:35:34,556
of characters?

2226
01:35:34,776 --> 01:35:37,266
Probably because no one in their
right mind would ever need to

2227
01:35:37,266 --> 01:35:38,816
or want to type something
like that

2228
01:35:38,816 --> 01:35:39,876
out in the real world, right.

2229
01:35:39,876 --> 01:35:41,596
It's just frankly,
it took me years

2230
01:35:41,596 --> 01:35:42,746
to just memorize it, frankly.

2231
01:35:43,106 --> 01:35:44,566
But now I got it.

2232
01:35:44,566 --> 01:35:46,986
And it's only something you need
again in these kinds of cases.

2233
01:35:46,986 --> 01:35:49,536
So is it relevant
to project zero?

2234
01:35:49,536 --> 01:35:52,066
Maybe. If you decide for
whatever reason that you want

2235
01:35:52,066 --> 01:35:54,046
to embed some HTML markup

2236
01:35:54,196 --> 01:35:56,306
for whatever reason,
it could be relevant.

2237
01:35:56,496 --> 01:35:59,186
But odds are this is not a
feature you will need to have

2238
01:35:59,236 --> 01:36:01,446
since again you're writing
your XML files from scratch

2239
01:36:01,446 --> 01:36:04,036
and have full discretion
over what to include or not.

2240
01:36:04,086 --> 01:36:07,296
And comments are as they
are in the world of XML.

2241
01:36:08,096 --> 01:36:10,416
Alright. Any questions on
the definitions of XML.

2242
01:36:11,046 --> 01:36:12,806
There's a little more
sophistication to it

2243
01:36:12,806 --> 01:36:14,096
than make up your own tags.

2244
01:36:14,686 --> 01:36:17,086
But at the end of the
day, it's very reminiscent

2245
01:36:17,086 --> 01:36:19,426
of the HTML world with
which you're familiar.

2246
01:36:19,896 --> 01:36:23,206
Alright. So let's now
actually use this.

2247
01:36:23,646 --> 01:36:26,106
I'm going to go ahead
and introduce by way

2248
01:36:26,106 --> 01:36:29,706
of examples an API that comes
with PHP called Simple XML.

2249
01:36:30,056 --> 01:36:30,996
It's pretty good.

2250
01:36:31,386 --> 01:36:34,606
This API is just a suite of
functions that comes with PHP5

2251
01:36:34,646 --> 01:36:38,366
that make it easier to parse
XML's, so that you do not need

2252
01:36:38,366 --> 01:36:40,036
to write software that reads

2253
01:36:40,036 --> 01:36:44,536
in open bracket word space
word equal, you don't have to,

2254
01:36:44,536 --> 01:36:46,226
it parse an individual XML file.

2255
01:36:46,456 --> 01:36:49,486
You can just say, here's a file
of XML or here's a big string

2256
01:36:49,486 --> 01:36:53,586
of XML, give me a tree
that represents this XML.

2257
01:36:53,586 --> 01:36:56,046
So there is a function in
PHP that comes with this API

2258
01:36:56,046 --> 01:36:59,106
that will literally hand
you a pointer or a reference

2259
01:36:59,106 --> 01:37:01,986
to the root node of
a hierarchical tree

2260
01:37:01,986 --> 01:37:04,326
that has been constructed
in memory.

2261
01:37:04,646 --> 01:37:05,786
What do we mean by tree?

2262
01:37:06,216 --> 01:37:07,986
Well we mean this
thing called the dom.

2263
01:37:08,266 --> 01:37:12,036
So here is a much simpler
example at top left of some XML.

2264
01:37:12,036 --> 01:37:12,666
Let me zoom in.

2265
01:37:13,126 --> 01:37:14,376
And notice that it's simple

2266
01:37:14,376 --> 01:37:15,896
because there's only
a few elements here.

2267
01:37:15,976 --> 01:37:17,506
So just try to wrap
your mind around this.

2268
01:37:17,986 --> 01:37:20,396
We have students root element.

2269
01:37:20,856 --> 01:37:23,036
A student child with
an attribute of one

2270
01:37:23,036 --> 01:37:26,506
and then two children beneath
called name and status.

2271
01:37:27,036 --> 01:37:28,766
So what do I mean when
I say there's a function

2272
01:37:28,766 --> 01:37:31,416
that will parse this
string of XML

2273
01:37:31,596 --> 01:37:35,056
and hand you back a
reference to a node in a tree.

2274
01:37:35,376 --> 01:37:39,036
What it means is that PHP and
this function I'm referring

2275
01:37:39,036 --> 01:37:44,486
to is going to build up
a picture like this here.

2276
01:37:45,086 --> 01:37:48,196
So at the very top, we have
first what we'll call the

2277
01:37:48,196 --> 01:37:49,086
document node.

2278
01:37:49,366 --> 01:37:50,976
This is not the root element.

2279
01:37:51,526 --> 01:37:53,606
So ironically, XML
has root elements,

2280
01:37:53,916 --> 01:37:56,546
but when you build a tree the
root element is not the root

2281
01:37:56,546 --> 01:37:57,066
of the tree.

2282
01:37:57,416 --> 01:37:58,306
Now why is that?

2283
01:37:58,446 --> 01:38:01,446
Well it's motivated by the fact
that even in my simple example,

2284
01:38:01,446 --> 01:38:02,976
what did I have above
the root element?

2285
01:38:07,046 --> 01:38:07,376
>> Comment.

2286
01:38:07,376 --> 01:38:08,826
>> Yeah. A comment.

2287
01:38:08,826 --> 01:38:09,416
And that's valid.

2288
01:38:09,476 --> 01:38:10,186
You can do that.

2289
01:38:10,646 --> 01:38:13,176
But if you can have
comments at the top

2290
01:38:13,176 --> 01:38:16,086
of your file before the
root element, and you want

2291
01:38:16,086 --> 01:38:19,746
to build a tree out of this
thing, you now need a new root

2292
01:38:19,966 --> 01:38:23,826
for the data structure in memory
so that you can hang on to

2293
01:38:23,826 --> 01:38:25,746
that comment and on
to the root node,

2294
01:38:25,896 --> 01:38:29,056
and so that special root is
called the document element,

2295
01:38:29,056 --> 01:38:30,426
depicted here as a rectangle.

2296
01:38:30,796 --> 01:38:32,626
So the two children
of document here,

2297
01:38:32,626 --> 01:38:35,496
as implied by the downward
pointing arrows is a comment

2298
01:38:35,496 --> 01:38:38,346
on the left and then an
element node on the right,

2299
01:38:38,596 --> 01:38:43,006
the element for the students tag
that we saw in the XML fragment.

2300
01:38:43,006 --> 01:38:44,816
And the order matters, at
least when you draw it,

2301
01:38:45,096 --> 01:38:47,936
left means it's the first child,
right means it's second child.

2302
01:38:48,306 --> 01:38:49,876
Now what are the
children of students?

2303
01:38:50,226 --> 01:38:52,156
I claim that it has
three children.

2304
01:38:52,936 --> 01:38:54,136
And just as a sanity check,

2305
01:38:54,136 --> 01:38:56,726
what are the three
children of student?

2306
01:38:56,726 --> 01:38:59,416
Let me put the XML on
the screen as well.

2307
01:39:03,076 --> 01:39:05,376
What are the three
children of student?

2308
01:39:05,376 --> 01:39:07,386
And here is where I said
we'd come back to this sort

2309
01:39:07,386 --> 01:39:09,496
of weirder interpretation
of children.

2310
01:39:11,106 --> 01:39:11,636
Yeah, Isaac.

2311
01:39:11,636 --> 01:39:13,696
>> Name and status.

2312
01:39:13,856 --> 01:39:17,196
>> Name and status of
children of student.

2313
01:39:17,626 --> 01:39:19,596
But how about the
children of students?

2314
01:39:20,306 --> 01:39:23,896
>> Student name and [inaudible].

2315
01:39:24,156 --> 01:39:25,456
>> Well, one for three.

2316
01:39:26,586 --> 01:39:28,196
So it's not name and
status, because name

2317
01:39:28,196 --> 01:39:31,866
and status are again
children of student, singular.

2318
01:39:33,216 --> 01:39:36,776
So there's clearly at least
one child or students, right.

2319
01:39:36,846 --> 01:39:37,896
Everyone would probably agree

2320
01:39:37,896 --> 01:39:40,336
that student is a
child of students.

2321
01:39:41,116 --> 01:39:43,546
But I claim that in some
interpretation there's actually

2322
01:39:43,546 --> 01:39:44,776
three children of students.

2323
01:39:44,776 --> 01:39:45,636
What are the other two, Jack?

2324
01:39:45,636 --> 01:39:48,106
>> The space before
and after the students.

2325
01:39:48,106 --> 01:39:49,026
>> Yeah. Exactly.

2326
01:39:49,026 --> 01:39:52,076
So, you kind of have to, we've
kind of learned as a species

2327
01:39:52,076 --> 01:39:54,486
to ignore white space in
this case when programming.

2328
01:39:54,866 --> 01:39:58,146
But notice that this is really a
backslash N. This is probably a

2329
01:39:58,146 --> 01:40:01,716
space bar, space bar, or back
slash T. So there's some chunk

2330
01:40:01,716 --> 01:40:04,086
of white space there
that the user has hit

2331
01:40:04,086 --> 01:40:05,196
on his or her keyboard.

2332
01:40:05,506 --> 01:40:08,766
So if we kind of clump that all
together as one chunk of text,

2333
01:40:09,146 --> 01:40:11,016
that's arguably a
node in the tree.

2334
01:40:11,016 --> 01:40:12,386
And it's what we'll
call a text node.

2335
01:40:12,586 --> 01:40:14,006
And indeed that's
what we've drawn here.

2336
01:40:14,006 --> 01:40:17,726
The text node here is backlash
N backslash T. Now technically,

2337
01:40:17,726 --> 01:40:20,256
that could be two
nodes, two text nodes,

2338
01:40:20,256 --> 01:40:22,156
one with backslash N,
one with backslash T.

2339
01:40:22,156 --> 01:40:23,186
That would also be legitimate.

2340
01:40:23,536 --> 01:40:29,926
However, almost all, almost all
XML browser should join together

2341
01:40:29,926 --> 01:40:31,886
adjacent text nodes
into just one.

2342
01:40:31,886 --> 01:40:33,766
So it's safe to assume
you'll just get this one

2343
01:40:33,766 --> 01:40:34,686
as I've drawn here.

2344
01:40:34,986 --> 01:40:37,146
Now we have the student element
and then over to the right,

2345
01:40:37,176 --> 01:40:39,426
what should be this element
here that's slightly off screen?

2346
01:40:39,886 --> 01:40:42,346
What's the contents
on this node?

2347
01:40:43,006 --> 01:40:48,256
So it means what
comes after student?

2348
01:40:48,416 --> 01:40:50,136
What's that character I'm
pointing at with the green?

2349
01:40:50,136 --> 01:40:50,286
Yeah. Jack.

2350
01:40:50,736 --> 01:40:54,006
>> It's a new line.

2351
01:40:55,116 --> 01:40:55,946
>> Just a new line.

2352
01:40:55,946 --> 01:40:57,636
And indeed if we scroll
over to the right,

2353
01:40:57,636 --> 01:40:59,256
that's what I claim
is in that node.

2354
01:40:59,736 --> 01:41:01,956
Alright. You don't see
because it's white space,

2355
01:41:02,026 --> 01:41:04,106
but it is in fact there if
you hit it on the keyboard.

2356
01:41:04,386 --> 01:41:06,046
Now what's the deal with ID?

2357
01:41:06,046 --> 01:41:08,126
Now, this is just
an artist rendition.

2358
01:41:08,396 --> 01:41:11,176
But I decided to draw
the attribute as sort

2359
01:41:11,176 --> 01:41:14,366
of a horizontal thing hanging
off of the students element.

2360
01:41:14,406 --> 01:41:15,036
Why is that?

2361
01:41:15,356 --> 01:41:18,136
Well it's not correct to
draw an attribute as an child

2362
01:41:18,136 --> 01:41:21,496
because it itself cannot have
children, so I arbitrarily,

2363
01:41:21,496 --> 01:41:23,306
and just because it fit
nicely on the screen,

2364
01:41:23,546 --> 01:41:26,906
drew the attribute to the right
hand side there instead of down.

2365
01:41:26,906 --> 01:41:28,466
So that's just fundamentally
different,

2366
01:41:28,656 --> 01:41:31,726
but again this is just again
an interpretation of a dom.

2367
01:41:32,196 --> 01:41:33,756
It doesn't mean this
things literally hangs off

2368
01:41:33,756 --> 01:41:34,756
to the right in memory.

2369
01:41:35,176 --> 01:41:36,806
Alright. So what are the
children of students?

2370
01:41:36,846 --> 01:41:37,746
This one's got a lot.

2371
01:41:37,746 --> 01:41:39,746
It's got some white space, name,

2372
01:41:39,746 --> 01:41:42,066
white space, status,
white space.

2373
01:41:42,426 --> 01:41:43,336
And at the end of the day,

2374
01:41:43,396 --> 01:41:45,716
we're going to throw away
all of this white space.

2375
01:41:45,716 --> 01:41:48,576
But realize that truly
underneath the hood there are

2376
01:41:48,576 --> 01:41:50,806
these nodes having
been built up in RAM

2377
01:41:50,956 --> 01:41:52,326
when reading this XML file.

2378
01:41:52,636 --> 01:41:55,496
Lastly, it turns out that
name itself has a child

2379
01:41:56,046 --> 01:41:57,436
and this is one of
the real motivations

2380
01:41:57,436 --> 01:41:58,626
for talking about text nodes.

2381
01:41:58,936 --> 01:42:02,046
Finally, we have a text node
with actual interesting content,

2382
01:42:02,246 --> 01:42:06,576
jim bob, for Jim Bob, that
is a child of name and status

2383
01:42:06,576 --> 01:42:10,606
as a child of graduate, which is
the status of Jim Bob in school.

2384
01:42:11,406 --> 01:42:12,316
Okay. So in short.

2385
01:42:12,436 --> 01:42:15,236
You have an XML file,
either in a file or as

2386
01:42:15,336 --> 01:42:17,246
in a string variable in PHP.

2387
01:42:17,246 --> 01:42:21,066
You call a function in the
simple XML API that's going

2388
01:42:21,066 --> 01:42:23,186
to parse that string,
or that file.

2389
01:42:23,406 --> 01:42:25,396
What are you going to get
back as the return value?

2390
01:42:25,646 --> 01:42:28,206
You're going to get back
the address or reference

2391
01:42:28,206 --> 01:42:30,236
or pointer-- think of it
however you'd like for now--

2392
01:42:30,546 --> 01:42:34,466
to that document node that you
can then traverse, recursively,

2393
01:42:34,466 --> 01:42:36,926
hierarchically, however you
want to navigate this document

2394
01:42:36,926 --> 01:42:37,736
and pluck out the data.

2395
01:42:38,096 --> 01:42:39,796
So what's the relevance
to project zero?

2396
01:42:39,976 --> 01:42:42,336
You're going to have to come up
with a model for your pizza menu

2397
01:42:42,516 --> 01:42:44,076
where maybe you have
a menu element

2398
01:42:44,076 --> 01:42:47,526
and maybe you've got a pizza's
element and a sandwiches element

2399
01:42:47,526 --> 01:42:48,836
or something like
that, you're going

2400
01:42:48,836 --> 01:42:52,026
to need a way programmatically
to travel that tree and figure

2401
01:42:52,026 --> 01:42:53,736
out what types of
pizzas are there,

2402
01:42:53,736 --> 01:42:54,686
what kind of subs are there,

2403
01:42:54,686 --> 01:42:56,416
what kinds of salads
are there, and the like.

2404
01:42:56,726 --> 01:43:00,236
So this is where we're going
with this, this conversation.

2405
01:43:00,746 --> 01:43:04,366
So besides dom, and let, oh, I
didn't even use the buzz word.

2406
01:43:04,726 --> 01:43:06,406
DOM, document object model.

2407
01:43:06,716 --> 01:43:07,446
This was DOM.

2408
01:43:07,856 --> 01:43:11,486
So document object model refers
to the in-memory representation

2409
01:43:11,796 --> 01:43:14,096
of an XML document
or an HTML document

2410
01:43:14,476 --> 01:43:15,966
in this sort of tree fashion.

2411
01:43:16,266 --> 01:43:17,666
And again, this is
something we'll come back

2412
01:43:17,806 --> 01:43:19,226
to in the context of JAVA script

2413
01:43:19,496 --> 01:43:21,246
since it's even more
common these days

2414
01:43:21,246 --> 01:43:24,666
to traverse DOM structures
[inaudible] client side using

2415
01:43:24,666 --> 01:43:25,216
JAVA script.

2416
01:43:25,786 --> 01:43:27,066
So let's take an example now.

2417
01:43:27,066 --> 01:43:29,136
RSS. How many of you
actually read RSS feeds?

2418
01:43:30,066 --> 01:43:30,996
Okay. So a few of you.

2419
01:43:31,086 --> 01:43:32,116
Those are XML files.

2420
01:43:32,306 --> 01:43:35,656
The root element of an RSS
feed is open bracket RSS

2421
01:43:36,376 --> 01:43:37,226
close bracket.

2422
01:43:37,226 --> 01:43:39,086
And it's just XML,
the rest of it.

2423
01:43:39,356 --> 01:43:41,866
Now there's a whole bunch of
child elements and descendants

2424
01:43:41,866 --> 01:43:43,176
and some weird attributes
in there

2425
01:43:43,176 --> 01:43:44,696
so that you can store
links and pictures

2426
01:43:44,696 --> 01:43:45,696
and all of that these days.

2427
01:43:45,916 --> 01:43:48,976
But at the end of the day,
RSS is just an XML file

2428
01:43:48,976 --> 01:43:50,506
and it actually,
the specification

2429
01:43:50,506 --> 01:43:52,316
for this language
lives coincidentally

2430
01:43:52,316 --> 01:43:54,666
at the law school, that URL,
if you'd like to read up on it.

2431
01:43:55,026 --> 01:43:56,576
But here's a representative
snippet.

2432
01:43:57,046 --> 01:44:01,036
This is an, this is an RSS
feed with no actual content,

2433
01:44:01,196 --> 01:44:03,756
but it shows you the
minimum required elements

2434
01:44:03,786 --> 01:44:05,666
that you must have
in an RSS feed.

2435
01:44:05,916 --> 01:44:07,916
You must have the
RSS element at top.

2436
01:44:08,156 --> 01:44:10,266
You must have a channel
element as a child,

2437
01:44:10,606 --> 01:44:12,746
a channel must have a
title description in link,

2438
01:44:12,746 --> 01:44:16,316
and then it must have one or
more item elements, or zero

2439
01:44:16,316 --> 01:44:19,826
or more item elements where an
item represents a new story,

2440
01:44:19,926 --> 01:44:21,656
something that's
in the RSS feed.

2441
01:44:21,656 --> 01:44:25,186
And for those unfamiliar,
RSS and RSS readers are

2442
01:44:25,186 --> 01:44:28,646
about syndicating news in a
standard machine readable format

2443
01:44:28,906 --> 01:44:32,986
so that you can use Google
reader or Safari or Chrome or IE

2444
01:44:32,986 --> 01:44:35,446
to read the day's
news without going

2445
01:44:35,446 --> 01:44:37,786
to ten different places websites

2446
01:44:37,786 --> 01:44:39,976
to read them there
in their usual way.

2447
01:44:40,466 --> 01:44:43,356
So an item has a few
elements as children.

2448
01:44:43,356 --> 01:44:46,156
A GUID which is unique
identifier which is supposed

2449
01:44:46,156 --> 01:44:49,396
to uniquely identify that
article or that item, a title,

2450
01:44:49,396 --> 01:44:51,996
a link, a description, category,
and a publication date.

2451
01:44:52,366 --> 01:44:55,066
So this is an RSS feed
and let's go ahead now

2452
01:44:55,316 --> 01:44:57,296
and do something
interesting with this.

2453
01:44:57,296 --> 01:45:00,826
Let me go into the appliance
where I have an example here

2454
01:45:00,826 --> 01:45:05,746
in the XML directory and
let's open up lectures.xml.

2455
01:45:06,086 --> 01:45:09,606
So in advance of tonight, I
decided to make my own XML file

2456
01:45:10,056 --> 01:45:13,776
that looks like this, a
lectures root element,

2457
01:45:14,256 --> 01:45:15,836
then lecture children,

2458
01:45:16,056 --> 01:45:19,086
each lecture has an attribute
called number with a value,

2459
01:45:19,486 --> 01:45:22,486
and then below that is a
title, and a date's element

2460
01:45:22,796 --> 01:45:24,826
and then there's a
resources element,

2461
01:45:24,826 --> 01:45:26,966
and then there's resource,
resource, resource,

2462
01:45:27,006 --> 01:45:29,566
depending on how many resources
we gave out that night.

2463
01:45:29,756 --> 01:45:31,756
And each resource
can have a format.

2464
01:45:32,256 --> 01:45:34,226
So in other words this
is just something I came

2465
01:45:34,226 --> 01:45:36,636
up with arbitrarily but I gave
some thought to its design

2466
01:45:36,636 --> 01:45:39,786
so that I'd have minimal
redundancy and also the ability

2467
01:45:39,966 --> 01:45:43,506
to distribute certain handouts
in multiple formats, pdf,

2468
01:45:43,766 --> 01:45:46,736
or zip, or anything
else like that.

2469
01:45:47,226 --> 01:45:48,766
So for instance, in
the very first lecture,

2470
01:45:48,766 --> 01:45:51,686
we gave out some slides, and
here is the URL to those slides.

2471
01:45:51,686 --> 01:45:53,266
It's a long URL,
but it ends in .pdf.

2472
01:45:53,266 --> 01:45:55,746
We also gave out the
syllabus that day.

2473
01:45:55,746 --> 01:46:00,976
And again, realize that I have
put a format element as a child

2474
01:46:00,976 --> 01:46:03,666
of a resource simply because
if we wanted to release

2475
01:46:03,666 --> 01:46:06,066
like a word document for
the syllabus, we could,

2476
01:46:06,356 --> 01:46:07,676
just by adding another format

2477
01:46:07,996 --> 01:46:09,956
without calling it
a separate resource,

2478
01:46:09,956 --> 01:46:11,196
same resource, different format.

2479
01:46:11,476 --> 01:46:12,786
So again, this is representative

2480
01:46:12,786 --> 01:46:16,266
of a typical XML design
decision, so as to accommodate

2481
01:46:16,266 --> 01:46:17,526
that kind of of versatility.

2482
01:46:17,526 --> 01:46:21,736
And if we scroll down, we'll
see indeed here's a good one.

2483
01:46:21,736 --> 01:46:23,806
Once we get to source code,
if you've downloaded stuff

2484
01:46:23,806 --> 01:46:25,036
from the course's website yet,

2485
01:46:25,366 --> 01:46:27,856
recall that source code
we distribute as an index,

2486
01:46:27,856 --> 01:46:30,716
which means you can browse it
in your browser, PDF and a zip.

2487
01:46:30,846 --> 01:46:33,526
So here's an actual example of
distributing multiple formats

2488
01:46:33,526 --> 01:46:35,436
for the same conceptual
resource.

2489
01:46:35,436 --> 01:46:36,656
In this case, source code.

2490
01:46:37,026 --> 01:46:39,516
Short, could have done this
any number of other ways.

2491
01:46:39,516 --> 01:46:41,746
My names for tags are
completely arbitrary.

2492
01:46:41,746 --> 01:46:43,266
This is not some
lecture standard

2493
01:46:43,266 --> 01:46:44,246
that the world has agreed on.

2494
01:46:44,446 --> 01:46:46,946
There's just my little
ole me's format for XML,

2495
01:46:47,126 --> 01:46:48,306
similarly will you need to come

2496
01:46:48,306 --> 01:46:51,476
up with your own menu.xml
file for this pizzeria.

2497
01:46:51,746 --> 01:46:53,326
But what I can do
now that I have this

2498
01:46:53,326 --> 01:46:55,546
in XML is something like this.

2499
01:46:55,856 --> 01:46:59,706
In my XML directory, I
have the lectures.php file

2500
01:47:00,076 --> 01:47:00,836
which looks like this.

2501
01:47:01,266 --> 01:47:04,246
For the most part, this
is just an HTML 5 page

2502
01:47:04,586 --> 01:47:07,396
with a hard-coded title,
and then an unordered list

2503
01:47:07,746 --> 01:47:11,066
and here is that function
I promised existed earlier.

2504
01:47:11,066 --> 01:47:12,306
And there's a few
variants of this.

2505
01:47:12,756 --> 01:47:14,536
This is simple XML load file,

2506
01:47:14,536 --> 01:47:16,406
there's also simple
XML load string,

2507
01:47:16,456 --> 01:47:17,336
and there's a few others.

2508
01:47:17,566 --> 01:47:19,406
There's also an object
oriented version of this,

2509
01:47:19,406 --> 01:47:21,056
but I'm using the
procedural function.

2510
01:47:21,336 --> 01:47:22,326
And notice what I'm doing.

2511
01:47:22,326 --> 01:47:26,326
I'm calling simple XML load
file quote unquote lectures.xml.

2512
01:47:26,326 --> 01:47:28,236
And that, frankly it
couldn't get more explicit,

2513
01:47:28,236 --> 01:47:29,456
that is loading that file.

2514
01:47:30,126 --> 01:47:31,316
What is returning?

2515
01:47:31,536 --> 01:47:34,376
It's returning to me
a reference to a tree.

2516
01:47:34,376 --> 01:47:37,176
That hierarchical picture
we just looked at and just

2517
01:47:37,176 --> 01:47:38,726
to remind myself of that fact,

2518
01:47:38,856 --> 01:47:40,906
I'm calling my variable
dollar sign dom.

2519
01:47:41,456 --> 01:47:44,136
So now, with dom represents
that the root of that tree

2520
01:47:44,206 --> 01:47:46,496
and because this trees
arrows point downward

2521
01:47:46,496 --> 01:47:49,626
from that root element, I
can access any other node

2522
01:47:49,626 --> 01:47:53,006
in the tree just stepping
downwards, down, down, down.

2523
01:47:53,006 --> 01:47:54,206
So how do I step downward?

2524
01:47:54,436 --> 01:47:57,286
Well what's nice about
the simple XML API is

2525
01:47:57,396 --> 01:47:59,136
that frankly they
make it really simple.

2526
01:47:59,136 --> 01:48:00,746
I mean that's literally
where it gets its name.

2527
01:48:01,096 --> 01:48:02,356
So here's a for each statement.

2528
01:48:02,686 --> 01:48:09,146
For each dom arrow X path
quote unquote lectures/lecture.

2529
01:48:09,146 --> 01:48:12,046
So X path is XML path language.

2530
01:48:12,196 --> 01:48:15,126
It's a feature of the
XML world that allows you

2531
01:48:15,216 --> 01:48:18,786
to traverse hierarchical data
structures, namely XML files,

2532
01:48:19,196 --> 01:48:22,216
using paths that look like
file system paths, C colon,

2533
01:48:22,216 --> 01:48:24,686
backslash, program files,
backslash, word, whatever,

2534
01:48:25,146 --> 01:48:26,756
so using paths like that

2535
01:48:26,906 --> 01:48:28,726
to navigate a hierarchical
document.

2536
01:48:29,026 --> 01:48:32,636
So in this case, the X path
function always returns an array

2537
01:48:33,266 --> 01:48:36,656
of nodes that match
your X path expression.

2538
01:48:37,096 --> 01:48:38,366
So what am I asking for?

2539
01:48:38,366 --> 01:48:42,206
I'm saying give me all
of the lecture elements

2540
01:48:42,436 --> 01:48:43,786
that are children of what?

2541
01:48:44,166 --> 01:48:44,356
>> Lectures.

2542
01:48:46,396 --> 01:48:49,566
>> The lectures element
which is a child of nothing.

2543
01:48:49,756 --> 01:48:51,966
The leading slash means
that's the root element.

2544
01:48:52,666 --> 01:48:56,606
So if I get back one or more
lectures, this for each loop

2545
01:48:56,606 --> 01:48:58,936
like we saw last week is going
to iterate over that array

2546
01:48:58,936 --> 01:49:01,236
and on each iteration it's
going to update the value

2547
01:49:01,236 --> 01:49:05,426
of dollar sign lecture
to be that lecture and so

2548
01:49:05,426 --> 01:49:08,126
on each iteration of this loop
we're going to print an LI

2549
01:49:08,716 --> 01:49:11,976
and a close LI inside of which
is going to be lecture title.

2550
01:49:12,306 --> 01:49:14,636
So this too refers to
the simple XML API.

2551
01:49:15,196 --> 01:49:18,176
If you just want to start at
a node and go one level deeper

2552
01:49:18,176 --> 01:49:19,366
without doing like a search.

2553
01:49:19,406 --> 01:49:21,546
X path is allowing me to
search the whole tree.

2554
01:49:21,826 --> 01:49:24,616
But if I'm at a lecture and I
want to get a lecture's title,

2555
01:49:25,196 --> 01:49:29,516
recall that title is its child
in the document we just showed.

2556
01:49:30,046 --> 01:49:32,286
This will grab its
title from the node.

2557
01:49:32,956 --> 01:49:35,736
So if this is a little unclear
in code, let's just look at this

2558
01:49:35,736 --> 01:49:37,866
in a browser then we
can walk through it.

2559
01:49:38,916 --> 01:49:39,836
Here we go.

2560
01:49:40,196 --> 01:49:41,226
That's the XML file.

2561
01:49:41,226 --> 01:49:43,856
Let me open up the
PHP file, voila.

2562
01:49:44,166 --> 01:49:48,366
My XML, my PHP file has this
dynamically generated list

2563
01:49:48,526 --> 01:49:51,086
of lecture titles which
looks really simple

2564
01:49:51,086 --> 01:49:54,806
and underneath the hood notice
is only HTML and as I mentioned,

2565
01:49:54,806 --> 01:49:57,446
disclaimed last week, it's
not beautifully pretty printed

2566
01:49:57,446 --> 01:50:00,306
because my PHP code is, my
HTML doesn't have to be,

2567
01:50:00,536 --> 01:50:02,356
but all of this came from where?

2568
01:50:02,746 --> 01:50:03,996
From that XML file.

2569
01:50:04,886 --> 01:50:08,896
So let's go back to the
XML file, lectures.xml.

2570
01:50:09,506 --> 01:50:10,756
How did I print the title?

2571
01:50:11,206 --> 01:50:13,736
Well notice that I
used X path to get all

2572
01:50:13,736 --> 01:50:15,496
of the lecture elements
in an array

2573
01:50:16,076 --> 01:50:18,806
by saying X path slash
lecture slash lecture

2574
01:50:18,996 --> 01:50:21,176
and that gives me an array
of size what, apparently?

2575
01:50:21,776 --> 01:50:25,586
If you recall from the
previous unordered list.

2576
01:50:25,716 --> 01:50:27,636
How many bullets were
there a moment ago?

2577
01:50:28,266 --> 01:50:28,386
Yeah.

2578
01:50:28,826 --> 01:50:29,026
>> Four.

2579
01:50:29,116 --> 01:50:29,706
>> There were four.

2580
01:50:29,706 --> 01:50:30,266
Why is that?

2581
01:50:30,386 --> 01:50:32,716
Well if we scroll through this,
we'll be, we're in tonight,

2582
01:50:32,716 --> 01:50:34,336
we're at lecture
three, zero index,

2583
01:50:34,336 --> 01:50:37,216
so tonight's the fourth lecture,
so we have lecture, lecture,

2584
01:50:37,336 --> 01:50:40,536
lecture, lecture, that's why we
got back an array of size four

2585
01:50:40,646 --> 01:50:43,026
and on each iteration of that
four loop, what was I printing?

2586
01:50:43,226 --> 01:50:45,026
I was printing each
lecture's title.

2587
01:50:45,116 --> 01:50:46,076
But what is title?

2588
01:50:46,116 --> 01:50:48,626
Title is a child of
what kind of element?

2589
01:50:49,516 --> 01:50:53,676
Lecture. So I simply have
to say lecture arrow title

2590
01:50:53,676 --> 01:50:54,916
and that gives me the title.

2591
01:50:55,256 --> 01:50:57,766
So this is again, where
simple XML gets its name.

2592
01:50:57,766 --> 01:50:59,186
It's frankly pretty simple

2593
01:50:59,226 --> 01:51:02,106
to navigate an XML
document using these arrows

2594
01:51:02,106 --> 01:51:03,886
and these X path expressions

2595
01:51:04,126 --> 01:51:06,536
because you can pretty much
address any part of the document

2596
01:51:06,536 --> 01:51:08,416
that you want and really
easily loop over it

2597
01:51:08,416 --> 01:51:09,446
which will again be useful

2598
01:51:09,446 --> 01:51:12,036
for dynamically generating
a pizza menu on a screen

2599
01:51:12,126 --> 01:51:14,676
out of one single XML file.

2600
01:51:15,106 --> 01:51:17,196
Now what else can we do here?

2601
01:51:17,376 --> 01:51:18,956
Number. What if I wanted

2602
01:51:18,956 --> 01:51:21,986
to display the lecture
number for each thing?

2603
01:51:22,286 --> 01:51:25,976
So suppose over here; let
me go back to my web page.

2604
01:51:26,246 --> 01:51:28,796
This is not all that useful
because I kind of have forgotten

2605
01:51:28,916 --> 01:51:31,146
in my unordered list what
the lecture number is.

2606
01:51:31,536 --> 01:51:32,816
So let's go ahead and do that.

2607
01:51:32,816 --> 01:51:35,236
Let me go in and first remind

2608
01:51:35,796 --> 01:51:39,096
that number is an attribute
and title is a child.

2609
01:51:39,226 --> 01:51:41,566
So our syntax is going to
have to be slightly different.

2610
01:51:41,566 --> 01:51:42,906
So I'm going to go
ahead and do this.

2611
01:51:43,576 --> 01:51:48,606
Inside of my LI, I'm going
to go ahead and say lecture

2612
01:51:49,536 --> 01:51:52,926
and then I want to go ahead
and print out the number.

2613
01:51:53,366 --> 01:51:54,176
So how do I do this?

2614
01:51:55,136 --> 01:51:58,996
Lecture open bracket
quote unquote N,

2615
01:51:59,516 --> 01:52:02,556
or what was it number or N?

2616
01:52:02,696 --> 01:52:09,606
Number quote unquote and then
I'll do like a colon here just

2617
01:52:09,606 --> 01:52:10,826
for formatting purposes.

2618
01:52:11,256 --> 01:52:13,206
So now notice then I'm
going to print the title.

2619
01:52:13,746 --> 01:52:14,966
So let's see what
the end result is.

2620
01:52:14,966 --> 01:52:16,276
Let me go back to my browser,

2621
01:52:16,636 --> 01:52:18,596
reload the page, and
now we have that.

2622
01:52:19,146 --> 01:52:21,166
So we have really just
two pieces of syntax.

2623
01:52:21,166 --> 01:52:22,366
One is attributes,

2624
01:52:22,366 --> 01:52:25,646
which apparently involves
square bracket notation just

2625
01:52:25,646 --> 01:52:28,206
as though it were an associative
array, but it's not really.

2626
01:52:28,206 --> 01:52:29,706
It's an XML attribute.

2627
01:52:29,936 --> 01:52:31,416
And the arrow notation allows me

2628
01:52:31,416 --> 01:52:33,526
to traverse things
hierarchically.

2629
01:52:34,366 --> 01:52:37,256
So it turns X path,
though is more powerful.

2630
01:52:37,536 --> 01:52:40,776
Suppose that for whatever
reason I only wanted to select

2631
01:52:41,336 --> 01:52:44,816
for this page, lecture number 3.

2632
01:52:45,426 --> 01:52:47,186
I need to apply some
kind of filter.

2633
01:52:47,456 --> 01:52:49,096
Now, I could do it the
old school approach

2634
01:52:49,096 --> 01:52:52,826
of well just do your X path
expression, get back an array

2635
01:52:52,826 --> 01:52:54,666
with all the lectures,
which in this case is four,

2636
01:52:54,836 --> 01:52:56,046
and then just have
an if condition.

2637
01:52:56,356 --> 01:53:00,116
And I could do something
correct but a little tedious,

2638
01:53:00,426 --> 01:53:09,566
like if lecture bracket N equals
equals three then I can go ahead

2639
01:53:09,566 --> 01:53:10,386
and do something.

2640
01:53:10,386 --> 01:53:11,076
So I could do that.

2641
01:53:11,076 --> 01:53:13,226
But it's a little inefficient
and I'm asking for all

2642
01:53:13,226 --> 01:53:15,456
of the lecture elements even
though I only care about one.

2643
01:53:15,796 --> 01:53:17,796
So it turns out X path
can do this for me.

2644
01:53:18,116 --> 01:53:20,066
I can introduce the
notion of a predicate

2645
01:53:20,516 --> 01:53:23,406
with a square bracket inside
of my X path expression

2646
01:53:23,886 --> 01:53:26,236
and then I can actually
add a qualifier

2647
01:53:26,236 --> 01:53:29,706
like number equals quote
unquote three close bracket.

2648
01:53:30,386 --> 01:53:33,886
And now, if I save the
file and go back to my page

2649
01:53:34,056 --> 01:53:40,076
and hit reload, I have screwed
up because lecture three,

2650
01:53:40,346 --> 01:53:46,456
lecture number three, because
I forgot the attribute.

2651
01:53:47,286 --> 01:53:48,596
Okay. Sorry, you
don't just say number.

2652
01:53:48,596 --> 01:53:49,816
At for attribute.

2653
01:53:50,036 --> 01:53:51,416
At number equals three.

2654
01:53:51,776 --> 01:53:52,856
Now let's go back and reload.

2655
01:53:52,856 --> 01:53:53,736
There it is.

2656
01:53:54,306 --> 01:53:58,046
So now, I've only selected
one node, not four,

2657
01:53:58,206 --> 01:53:59,556
with that X path expression.

2658
01:53:59,936 --> 01:54:01,346
So let's try to generalize this.

2659
01:54:01,446 --> 01:54:04,276
Turns out in X path you can
express yourself in this way.

2660
01:54:04,486 --> 01:54:05,666
This is sort of the canonical

2661
01:54:05,666 --> 01:54:09,046
if overwhelmingly
cryptic definition

2662
01:54:09,046 --> 01:54:10,656
of what's called
a location path.

2663
01:54:10,816 --> 01:54:13,226
So a location path is that
whole expression in quotes.

2664
01:54:13,506 --> 01:54:16,836
So each of these things between
the slashes is what's called a

2665
01:54:17,026 --> 01:54:18,836
step, step, step, step.

2666
01:54:19,106 --> 01:54:22,076
A step would be part of
the location path here.

2667
01:54:22,076 --> 01:54:23,906
In this case, there's two steps.

2668
01:54:24,176 --> 01:54:25,816
This one because
there is a slash there

2669
01:54:25,816 --> 01:54:26,866
and then this whole thing.

2670
01:54:27,466 --> 01:54:29,926
So axis, let's come back to,

2671
01:54:29,926 --> 01:54:31,896
node test let's come back
to, but here's predicate.

2672
01:54:31,896 --> 01:54:33,416
We just introduced the
idea of a predicate.

2673
01:54:33,416 --> 01:54:34,626
In this case, I'm filtering

2674
01:54:34,626 --> 01:54:37,036
on at sign number equals
quote unquote zero,

2675
01:54:37,036 --> 01:54:39,436
which is hopefully going
to give me lecture zero,

2676
01:54:39,946 --> 01:54:41,906
so now the whole thing
is a location path.

2677
01:54:42,396 --> 01:54:43,356
Now what's an axis.

2678
01:54:43,866 --> 01:54:47,606
Now thus far, we've been using
the default axis which is child.

2679
01:54:47,896 --> 01:54:50,366
So if you don't specify
the double colons

2680
01:54:50,366 --> 01:54:51,716
with the word child
in front of it,

2681
01:54:51,926 --> 01:54:53,946
X path just assumes
you want child.

2682
01:54:54,196 --> 01:54:55,906
But it turns out
there's other axes.

2683
01:54:55,906 --> 01:54:57,456
There's parent colon, colon.

2684
01:54:57,656 --> 01:54:59,126
There's sibling colon, colon.

2685
01:54:59,326 --> 01:55:00,946
There's preceding colon, colon.

2686
01:55:00,946 --> 01:55:02,546
There's following colon, colon.

2687
01:55:02,546 --> 01:55:04,046
There's descendant colon, colon.

2688
01:55:04,286 --> 01:55:06,656
In other words, you can
start at a given node

2689
01:55:07,036 --> 01:55:10,386
and identify a whole bunch of
nodes above it to the left of it

2690
01:55:10,386 --> 01:55:12,236
to the right of it
next to it below it,

2691
01:55:12,436 --> 01:55:14,876
thus far we've just been doing
one level below the so-called

2692
01:55:14,876 --> 01:55:16,786
child axis just because
it's the most common.

2693
01:55:17,116 --> 01:55:21,126
In fact the at sign here is
actually shorthand notation

2694
01:55:21,126 --> 01:55:23,686
for another axis and
that shorthand notation,

2695
01:55:24,046 --> 01:55:28,256
when exploded, is actually
as verbose as this.

2696
01:55:28,986 --> 01:55:30,216
So this is identical.

2697
01:55:30,326 --> 01:55:33,516
Attribute colon, colon, number
equals quote unquote three.

2698
01:55:33,756 --> 01:55:35,586
It's just, my God, no one
wants to ever type that,

2699
01:55:35,586 --> 01:55:38,246
the at sign is a nice
shorthand notation for it.

2700
01:55:38,396 --> 01:55:39,946
However, if I really
want to be anal,

2701
01:55:39,946 --> 01:55:43,836
I can do this really properly,
child colon, colon, child colon,

2702
01:55:43,836 --> 01:55:46,686
colon, and that now
is the same thing.

2703
01:55:47,146 --> 01:55:48,976
So how does this really
work fundamentally?

2704
01:55:49,296 --> 01:55:54,496
Well, when you start an X path
expression, and you use it

2705
01:55:54,496 --> 01:55:57,196
in something like PHP,
the first thing says,

2706
01:55:57,196 --> 01:56:00,026
the first thing says, the slash,

2707
01:56:00,276 --> 01:56:02,356
give me all of the nodes
that start at slash.

2708
01:56:02,606 --> 01:56:04,196
Fortunately, there's
generally only one,

2709
01:56:04,196 --> 01:56:05,876
there is only one,
the root element.

2710
01:56:06,316 --> 01:56:07,676
So hopefully child colon,

2711
01:56:07,676 --> 01:56:09,936
colon lectures matches
the root element.

2712
01:56:10,816 --> 01:56:14,246
Next, the slash means, okay
start from that result set,

2713
01:56:14,466 --> 01:56:16,696
that node set containing
all of the results

2714
01:56:16,696 --> 01:56:19,566
of that expression slash
lectures, which is one node,

2715
01:56:19,806 --> 01:56:23,746
and now grow or filter
the resulting node set

2716
01:56:23,746 --> 01:56:27,186
to include also anything
that's a child called lecture

2717
01:56:27,706 --> 01:56:29,856
of the lectures element.

2718
01:56:30,206 --> 01:56:32,946
It's a node test in the sense
that lecture is the name

2719
01:56:32,946 --> 01:56:34,396
of the node that
you want to match.

2720
01:56:34,396 --> 01:56:35,726
You could change it to a star

2721
01:56:35,726 --> 01:56:38,726
and that would give you
any children of lectures.

2722
01:56:39,046 --> 01:56:40,706
I only want the ones
called lecture,

2723
01:56:40,846 --> 01:56:42,576
even though frankly there
are no other children

2724
01:56:42,576 --> 01:56:43,426
because I wrote the file,

2725
01:56:43,426 --> 01:56:45,346
but that's really just a
design decision I made.

2726
01:56:45,786 --> 01:56:48,766
So at this point in the story,
I have all lecture elements

2727
01:56:48,766 --> 01:56:50,876
in my node set that are children

2728
01:56:50,876 --> 01:56:54,946
of a lectures element that's a
child of the document itself.

2729
01:56:55,646 --> 01:56:57,096
Lastly, you have this predicate.

2730
01:56:57,376 --> 01:57:00,016
The predicate says, okay, you've
got all these lecture nodes,

2731
01:57:00,226 --> 01:57:02,576
now go ahead and
include only the ones

2732
01:57:02,576 --> 01:57:06,146
that match this predicate
whereby their attribute called

2733
01:57:06,146 --> 01:57:08,526
number equals quote
unquote zero.

2734
01:57:08,886 --> 01:57:10,326
And notice a few details here.

2735
01:57:10,686 --> 01:57:12,846
The zero is quoted
because it's a string.

2736
01:57:12,846 --> 01:57:15,056
Almost everything in XML
is a string, even it looks

2737
01:57:15,056 --> 01:57:17,856
like a number, because an
XML file is a text file

2738
01:57:18,156 --> 01:57:20,306
and the equal sign is
a single equal sign,

2739
01:57:20,306 --> 01:57:22,276
it's not equals equals
as it would be

2740
01:57:22,276 --> 01:57:23,756
in most programming languages.

2741
01:57:24,096 --> 01:57:26,066
Also realize you can
have multiple predicates.

2742
01:57:26,066 --> 01:57:27,546
You could have had
a predicate here.

2743
01:57:27,546 --> 01:57:29,286
You could have one
over here and so forth.

2744
01:57:29,626 --> 01:57:32,586
You just think of these location
paths ultimately as these steps

2745
01:57:32,586 --> 01:57:34,466
that are either adding
or subtracting nodes

2746
01:57:34,466 --> 01:57:36,566
from the answer and
what's returned

2747
01:57:36,566 --> 01:57:39,136
in PHP is an array
of the final results.

2748
01:57:39,676 --> 01:57:43,836
Phew. That was a lot, too.

2749
01:57:44,456 --> 01:57:45,456
Any questions?

2750
01:57:46,046 --> 01:57:51,846
Alright. So it's time
for pizza ML discussion.

2751
01:57:52,266 --> 01:57:55,396
So in pizza ML, as you'll see
in the spec, there's going

2752
01:57:55,396 --> 01:57:56,626
to be a few components to it.

2753
01:57:56,626 --> 01:57:58,996
Let me go ahead and open
this up in a browser

2754
01:57:59,736 --> 01:58:01,816
and the specification
for this one, like other,

2755
01:58:01,886 --> 01:58:02,606
that's what the place used

2756
01:58:02,606 --> 01:58:04,216
to look before they
shut down, sadly.

2757
01:58:04,386 --> 01:58:05,396
It's delicious pizza.

2758
01:58:05,876 --> 01:58:08,856
What you'll see is that the
specs will have you walk

2759
01:58:08,856 --> 01:58:10,166
through a few steps typically.

2760
01:58:10,366 --> 01:58:12,626
The boxes at left at meant
to be check boxes so that

2761
01:58:12,626 --> 01:58:13,356
if you print it out you can

2762
01:58:13,356 --> 01:58:15,286
at least physically have the
gratification of saying done,

2763
01:58:15,286 --> 01:58:16,426
done, done, done, as you walk

2764
01:58:16,426 --> 01:58:18,846
through the spec. There'll be
some recommended reading here

2765
01:58:18,956 --> 01:58:20,876
that sometimes will
teach new stuff,

2766
01:58:20,876 --> 01:58:23,266
sometimes will recap old stuff
and realize there's plenty

2767
01:58:23,266 --> 01:58:24,276
of free stuff available.

2768
01:58:24,496 --> 01:58:26,436
The course's syllabus has
some recommended books.

2769
01:58:26,436 --> 01:58:28,416
None of them are required,
so really they're there

2770
01:58:28,416 --> 01:58:30,276
for your own edification
if of interest.

2771
01:58:30,556 --> 01:58:32,706
Plenty of free content
exists on the web.

2772
01:58:33,076 --> 01:58:36,546
You'll next see in the spec a
number of instructions for how

2773
01:58:36,546 --> 01:58:38,676
to download and install
the CS50 appliance.

2774
01:58:39,066 --> 01:58:41,006
In particular, if
you're a MAC user,

2775
01:58:41,186 --> 01:58:42,976
there is one step
you can do tonight.

2776
01:58:42,976 --> 01:58:46,076
When you go to the URL
that's cited in this section

2777
01:58:46,076 --> 01:58:48,476
of the spec, it has
instructions for how

2778
01:58:48,476 --> 01:58:49,456
to install the appliance.

2779
01:58:49,456 --> 01:58:51,456
To be clear, the appliance
will be posted by morning,

2780
01:58:51,766 --> 01:58:56,266
but you can download sooner
than that VMWare itself.

2781
01:58:56,266 --> 01:58:58,286
If you're a MAC user,
you need VMWare fusion.

2782
01:58:58,286 --> 01:59:02,766
Unfortunately, the only
offer a 30-day trial,

2783
01:59:02,766 --> 01:59:05,776
but we can give you access for
longer than 30 days, so go ahead

2784
01:59:05,776 --> 01:59:07,606
and follow the instructions
on the page there

2785
01:59:07,606 --> 01:59:09,226
and we'll explain
how to get the access

2786
01:59:09,266 --> 01:59:11,096
to the site license
that we have.

2787
01:59:11,096 --> 01:59:13,076
Windows and Linux
users have it easier

2788
01:59:13,076 --> 01:59:15,636
in that they actually have a
totally free version called

2789
01:59:15,636 --> 01:59:18,586
VMWare player which does the
same thing, but it's for Windows

2790
01:59:18,586 --> 01:59:20,236
and Linux, and the
instructions are also there.

2791
01:59:20,476 --> 01:59:22,956
So you can download and
install the hyper visor tonight

2792
01:59:22,956 --> 01:59:23,646
or tomorrow.

2793
01:59:23,876 --> 01:59:25,916
The fusion folks though will
have to wait to hear back

2794
01:59:25,916 --> 01:59:27,506
from us as to the
licensing issue.

2795
01:59:27,696 --> 01:59:30,246
And the appliance itself
will be up by morning.

2796
01:59:30,546 --> 01:59:33,206
And now we'll have a little
more tutorial here on setting

2797
01:59:33,206 --> 01:59:35,486
up a vhost, so the
discussion we had earlier

2798
01:59:35,486 --> 01:59:37,596
about creating the vhost
directory and so forth,

2799
01:59:37,826 --> 01:59:39,906
all of that is documented
here so that you know how

2800
01:59:39,906 --> 01:59:41,556
to create a project zero vhost.

2801
01:59:42,156 --> 01:59:44,626
Bitbucket, there's instructions
for how to get yourself set

2802
01:59:44,626 --> 01:59:46,616
up for bitbucket
for your own benefit

2803
01:59:46,616 --> 01:59:49,916
so that you don't run the risk
of losing content accidentally.

2804
01:59:50,346 --> 01:59:53,916
And then the real guts of the
spec, delicious XML walks you

2805
01:59:53,916 --> 01:59:55,526
through the menu itself.

2806
01:59:55,526 --> 01:59:57,766
So, I'm going to section
and to Peter's walk

2807
01:59:57,766 --> 02:00:00,306
through of the same, but
you'll see here an illusion

2808
02:00:00,306 --> 02:00:02,536
to a whole bunch of
categories of food

2809
02:00:02,856 --> 02:00:04,896
which are all present
here in the file.

2810
02:00:04,896 --> 02:00:07,116
So let me pull up here
the menu for three aces.

2811
02:00:07,496 --> 02:00:10,406
So this is literally the, a
PDF of the menu that they used

2812
02:00:10,406 --> 02:00:13,146
to have and you'll see that
they have pizzas and salads

2813
02:00:13,146 --> 02:00:14,446
and wraps and so forth.

2814
02:00:14,976 --> 02:00:17,266
But one of these things
that's kind of curious is

2815
02:00:17,266 --> 02:00:19,276
that if you go into the
store, you pick up this menu,

2816
02:00:19,276 --> 02:00:21,616
it's actually pretty obvious
to human how to order a pizza

2817
02:00:21,616 --> 02:00:22,746
or a salad or the like.

2818
02:00:23,236 --> 02:00:25,606
But if you're the
unfortunate programmer who has

2819
02:00:25,606 --> 02:00:29,306
to model this same set of data
in a database, or in our case

2820
02:00:29,306 --> 02:00:32,196
in a simple database like
an XML file, you'll realize

2821
02:00:32,196 --> 02:00:34,876
that these pizza guys really
were not being semantically

2822
02:00:34,876 --> 02:00:36,526
consistent throughout
their menu.

2823
02:00:36,806 --> 02:00:40,136
Which is to say, even though the
left hand side looks like a list

2824
02:00:40,136 --> 02:00:43,046
of pizzas all of which
are conceptually the same,

2825
02:00:43,046 --> 02:00:46,066
just pizzas with different
options, if you scroll

2826
02:00:46,066 --> 02:00:48,176
down further-- let
me zoom in here,

2827
02:00:48,626 --> 02:00:51,926
and Chrome is making
this PDF a little weird.

2828
02:00:51,956 --> 02:00:53,736
Let's open it in
preview instead.

2829
02:00:54,316 --> 02:00:57,296
Let's scroll down to the menu.

2830
02:00:57,736 --> 02:01:01,646
So you'll notice that you have
pizza with cheese, with onions,

2831
02:01:01,646 --> 02:01:04,196
with peppers, with broccoli,
dah, dah, dah, dah, dah,

2832
02:01:04,196 --> 02:01:06,146
and then at the bottom,
extra cheese.

2833
02:01:06,546 --> 02:01:08,196
So this is one of
these corner cases

2834
02:01:08,426 --> 02:01:11,396
where this does not
belong semantically

2835
02:01:11,446 --> 02:01:14,516
in the same column
of information.

2836
02:01:14,516 --> 02:01:18,146
Why? Because no one is going
to order extra cheese for $1.25

2837
02:01:18,146 --> 02:01:19,256
without a pizza, right?

2838
02:01:19,256 --> 02:01:21,146
So there's this corner case
here that you need to sort

2839
02:01:21,146 --> 02:01:23,226
of think about, well how
do you tolerate something

2840
02:01:23,226 --> 02:01:24,356
like extra cheese?

2841
02:01:24,486 --> 02:01:25,876
Is it a check box,
a radio button,

2842
02:01:25,876 --> 02:01:27,096
is it you type it in the notes.

2843
02:01:27,376 --> 02:01:29,576
So this is one of those
corner cases to run into.

2844
02:01:29,926 --> 02:01:34,616
Here, too, we have pizza was
the header for this section here

2845
02:01:34,776 --> 02:01:36,986
and it comes also
in small and large.

2846
02:01:37,296 --> 02:01:38,556
Now notice, these are
the kinds of things,

2847
02:01:38,556 --> 02:01:40,796
at least if you're me you really
notice, they capitalize small

2848
02:01:40,796 --> 02:01:41,996
and large differently here.

2849
02:01:42,336 --> 02:01:45,766
Down here, spaghetti or
ziti is a category of itself

2850
02:01:45,766 --> 02:01:48,596
and then the descriptions of
the line items are with this,

2851
02:01:48,596 --> 02:01:51,336
with that, or you can
have this crazy thing

2852
02:01:51,336 --> 02:01:54,006
which isn't really
quite the same.

2853
02:01:54,436 --> 02:01:55,686
We've got homemade lasagna.

2854
02:01:55,686 --> 02:01:56,706
So it's things like this.

2855
02:01:57,216 --> 02:02:00,036
If the category now in your
website is called homemade

2856
02:02:00,036 --> 02:02:02,486
lasagna, ravioli, or manicotti,

2857
02:02:03,316 --> 02:02:06,076
that's not really
just category, right?

2858
02:02:06,076 --> 02:02:07,926
That's like at least
a radio button

2859
02:02:07,926 --> 02:02:09,826
between three different
types of pasta.

2860
02:02:10,216 --> 02:02:12,756
So again, what looks pretty
straight forward to humans,

2861
02:02:12,756 --> 02:02:15,306
once you start thinking about as
a developer and as a designer,

2862
02:02:15,636 --> 02:02:17,976
it's not obvious how you would
represent this information.

2863
02:02:18,206 --> 02:02:21,456
So let's take a quick stab
at modeling this data just

2864
02:02:21,456 --> 02:02:23,976
to get you thinking along the
right lines, and then again

2865
02:02:23,976 --> 02:02:26,346
with Peter in Section,
he'll have an opportunity

2866
02:02:26,346 --> 02:02:28,956
to discuss other design
opportunities, or watch online

2867
02:02:28,956 --> 02:02:32,226
after the fact, as well as in
office hours tonight with Chris

2868
02:02:32,226 --> 02:02:33,736
and later on Wednesday.

2869
02:02:34,036 --> 02:02:36,886
So I need to represent,
create a file, as you'll see

2870
02:02:36,886 --> 02:02:38,466
in the spec called menu.xml.

2871
02:02:38,876 --> 02:02:41,346
Now the design of that
file is totally up to you,

2872
02:02:41,346 --> 02:02:43,836
so long as it adheres to
certain bulleted requirements

2873
02:02:43,836 --> 02:02:47,096
in the spec. So I need
minimally like a root element.

2874
02:02:47,236 --> 02:02:48,226
It could be called menu,

2875
02:02:48,226 --> 02:02:49,556
it could be called
anything you want.

2876
02:02:49,746 --> 02:02:52,266
Probably shouldn't be called
pizzas, because as we've seen,

2877
02:02:52,266 --> 02:02:53,766
they sell things besides pizzas.

2878
02:02:54,176 --> 02:02:57,266
So let's just take a group
stab for just a moment here,

2879
02:02:57,266 --> 02:02:59,816
what could be one of the first
children of a menu element.

2880
02:03:03,136 --> 02:03:03,386
>> Category.

2881
02:03:03,446 --> 02:03:06,206
>> Okay. So maybe a
category, so let's do that.

2882
02:03:06,206 --> 02:03:09,896
Open bracket category, and now
one of the categories, recall,

2883
02:03:09,896 --> 02:03:13,346
let's go back to it, was
pizzas, salads, grinders,

2884
02:03:13,346 --> 02:03:15,946
then the weird one, homemade
lasagna, ravioli, or manicotti.

2885
02:03:16,426 --> 02:03:19,206
So what more needs to be
in this category element?

2886
02:03:19,206 --> 02:03:21,436
Do I want to close
my angle bracket now?

2887
02:03:21,436 --> 02:03:22,636
Do I want an attribute?

2888
02:03:22,636 --> 02:03:24,266
Do I want to move
on to children?

2889
02:03:25,136 --> 02:03:26,166
Again, no right answer here.

2890
02:03:26,166 --> 02:03:27,056
But let's just brainstorm.

2891
02:03:27,586 --> 02:03:30,446
[Inaudible] An attribute, okay.

2892
02:03:30,446 --> 02:03:32,526
So maybe name equals pizzas.

2893
02:03:32,776 --> 02:03:34,906
Maybe. This; not unreasonable.

2894
02:03:35,166 --> 02:03:36,616
So close category.

2895
02:03:36,926 --> 02:03:39,306
And then in here, what
goes inside of a category?

2896
02:03:39,306 --> 02:03:41,616
Well let me look
back at the PDF.

2897
02:03:41,616 --> 02:03:43,336
If it's pizzas, tomato
and cheese.

2898
02:03:44,736 --> 02:03:48,486
Alright. So, do I want
to say this, though?

2899
02:03:50,296 --> 02:03:53,386
Maybe size equals small, right?

2900
02:03:54,296 --> 02:03:56,586
So this is where it
gets non-obvious.

2901
02:03:56,586 --> 02:03:58,806
Right, the XML language
is super simple.

2902
02:03:58,806 --> 02:04:00,456
A children attributes,
that's it.

2903
02:04:00,606 --> 02:04:02,486
You don't have much
expressive capabilities here.

2904
02:04:02,836 --> 02:04:04,576
But it's definitely
non-obvious how to do this.

2905
02:04:04,866 --> 02:04:08,576
Now give me an argument against
having a pizza element here.

2906
02:04:09,086 --> 02:04:13,456
Why might this be a bad idea?

2907
02:04:14,096 --> 02:04:17,416
>> If you have multiple
categories with pizzas

2908
02:04:17,506 --> 02:04:20,156
and salads, you would
want to be consistent

2909
02:04:20,156 --> 02:04:22,946
within those categories, so
call it like item [inaudible].

2910
02:04:22,946 --> 02:04:24,136
>> Good. Good.

2911
02:04:24,136 --> 02:04:25,936
I mean if we're going
through the trouble of sort

2912
02:04:25,936 --> 02:04:29,526
of generalizing the notion
of categories as we just did

2913
02:04:29,716 --> 02:04:32,266
and then refining the
definition of a category

2914
02:04:32,266 --> 02:04:34,746
with a name attribute
that is category specific,

2915
02:04:35,156 --> 02:04:37,226
why are we then hard-coding
pizza

2916
02:04:37,536 --> 02:04:39,136
which only belongs up there.

2917
02:04:39,326 --> 02:04:40,906
So we've sort of
generalized the category

2918
02:04:40,906 --> 02:04:42,396
but then hard-coded
the specifics.

2919
02:04:42,616 --> 02:04:45,956
So maybe better is indeed,
let's be self-consistent

2920
02:04:46,046 --> 02:04:51,116
and let's maybe say item
name equals tomato and cheese

2921
02:04:51,476 --> 02:04:54,876
and then I have to somehow
embody the notion of size

2922
02:04:54,936 --> 02:04:57,016
for instance and I don't
really know how to do that,

2923
02:04:57,306 --> 02:05:01,306
but I probably don't want to
do open bracket large, right?

2924
02:05:01,306 --> 02:05:03,186
I probably want to do
something like size

2925
02:05:03,186 --> 02:05:05,876
and then maybe type
equals large, or something.

2926
02:05:06,006 --> 02:05:07,176
Again, no right answer.

2927
02:05:07,516 --> 02:05:09,486
But the fact that I'm kind
of pausing and erasing

2928
02:05:09,486 --> 02:05:11,206
and starting over, it
should be the same kind

2929
02:05:11,206 --> 02:05:12,986
of thought process
you probably engage in

2930
02:05:13,226 --> 02:05:14,476
and already this is broken.

2931
02:05:14,476 --> 02:05:15,536
What wonderful surprise

2932
02:05:15,536 --> 02:05:17,736
that this menu gave
us an example here.

2933
02:05:18,106 --> 02:05:20,106
[ Inaudible ]

2934
02:05:20,196 --> 02:05:22,106
Yeah. So, already we
have that stupid issue.

2935
02:05:22,306 --> 02:05:23,296
And this is necessary.

2936
02:05:23,296 --> 02:05:29,076
If you have this, the simple XML
read file function will fail.

2937
02:05:29,166 --> 02:05:31,566
You'll get an error
because it's not valid XML.

2938
02:05:31,806 --> 02:05:33,206
So I would also make
this suggestion.

2939
02:05:33,206 --> 02:05:36,846
Before you spend an hour or
more sort of making your menu,

2940
02:05:37,056 --> 02:05:38,226
do it in baby steps, right.

2941
02:05:38,226 --> 02:05:40,386
Write a little bit of code,
run it through the equivalent

2942
02:05:40,386 --> 02:05:44,266
of a program like I just ran
you involving the lectures

2943
02:05:44,266 --> 02:05:45,886
but using your menu,
just to make sure

2944
02:05:45,886 --> 02:05:49,286
that with baby steps you're not
creating of a monster of a mess

2945
02:05:49,486 --> 02:05:50,566
to then go back and fix.

2946
02:05:50,966 --> 02:05:52,046
So also realize, too,

2947
02:05:52,046 --> 02:05:54,846
in the spec this could become
incredibly tedious to have

2948
02:05:54,846 --> 02:05:56,226
to type out this entire menu.

2949
02:05:56,526 --> 02:05:58,586
So realize that we specify
in the spec, you only need

2950
02:05:58,586 --> 02:06:00,696
to do a few from each
of the categories.

2951
02:06:00,956 --> 02:06:03,466
So this won't be an exercise in
tedium, but you'll have to trip

2952
02:06:03,466 --> 02:06:05,926
over some of these design
decisions and realize, too,

2953
02:06:05,926 --> 02:06:09,096
because we specify in the spec
that you only need to three

2954
02:06:09,096 --> 02:06:12,706
or more items from each of
the categories, you can also

2955
02:06:12,706 --> 02:06:14,736
in fairness avoid
certain corner cases

2956
02:06:14,736 --> 02:06:16,816
like the extra cheese
thing if you want.

2957
02:06:16,896 --> 02:06:19,216
That's really up to you as to
how you navigate those waters.

2958
02:06:19,216 --> 02:06:20,516
There's plenty of
things to trip over,

2959
02:06:21,056 --> 02:06:23,536
though in the aggregate
with this whole menu.

2960
02:06:23,706 --> 02:06:26,746
But let's do one other example
now, unrelated to menus,

2961
02:06:26,746 --> 02:06:29,526
but related to that
example involving RSS.

2962
02:06:30,016 --> 02:06:32,536
So that was our lecture example.

2963
02:06:32,536 --> 02:06:34,606
Let me go ahead and
open RSS1.php,

2964
02:06:34,946 --> 02:06:38,866
but let me first
highlight this URL;

2965
02:06:39,506 --> 02:06:43,506
let me first highlight
this URL here;

2966
02:06:46,196 --> 02:06:48,906
my browser's not cooperating.

2967
02:06:48,956 --> 02:06:51,506
Do it this way.

2968
02:06:52,106 --> 02:06:53,016
Okay. There we go.

2969
02:06:54,046 --> 02:06:55,416
So first, let me copy that URL;

2970
02:06:55,486 --> 02:06:57,936
let me then visit
it in my browser.

2971
02:06:58,166 --> 02:07:00,816
And here's the problem with
RSS, at least from a developer.

2972
02:07:01,016 --> 02:07:02,756
This is not the RSS feed.

2973
02:07:02,756 --> 02:07:06,126
This is the browser's
rendition of an RSS feed

2974
02:07:06,126 --> 02:07:09,126
in a more user-friendly
way with stuff that's not

2975
02:07:09,126 --> 02:07:10,556
in the actual RSS file.

2976
02:07:10,806 --> 02:07:13,126
In fact, if I view the source
of this, odds are depending

2977
02:07:13,126 --> 02:07:15,736
on the browser, I'll see
HTML, and I won't see RSS.

2978
02:07:16,256 --> 02:07:17,336
So there are ways around this.

2979
02:07:17,336 --> 02:07:19,316
Let me actually open
up my terminal instead.

2980
02:07:19,316 --> 02:07:21,446
And what I'm going
to do is this.

2981
02:07:21,446 --> 02:07:25,916
I'm going to type W get for web
get, then I'm going to paste

2982
02:07:25,916 --> 02:07:27,976
in this URL and then hit enter.

2983
02:07:28,176 --> 02:07:30,676
What's nice about the W get
command, which exists on a lot

2984
02:07:30,676 --> 02:07:34,326
of platforms like Linux, is now
I have a file called technology,

2985
02:07:34,476 --> 02:07:35,886
and here is the RSS file.

2986
02:07:36,096 --> 02:07:38,446
Now the specifics of
this RSS file are not all

2987
02:07:38,446 --> 02:07:39,766
that interesting for us tonight.

2988
02:07:40,016 --> 02:07:44,036
Realize that they do adhere to
the pub date and title and link

2989
02:07:44,036 --> 02:07:46,576
and description, all those
place holders I promised existed

2990
02:07:46,576 --> 02:07:48,606
in RSS file, there
in this one as well,

2991
02:07:48,606 --> 02:07:50,146
in addition to a
bunch of other stuff.

2992
02:07:50,346 --> 02:07:52,186
Adam is a alternative
file format

2993
02:07:52,186 --> 02:07:53,816
and there's name space
support in this thing.

2994
02:07:54,096 --> 02:07:57,196
But in short, at the end of
the day, this is an RSS feed

2995
02:07:57,456 --> 02:08:00,046
and it has channel
and item, and item,

2996
02:08:00,046 --> 02:08:01,146
and item, and item, and item.

2997
02:08:01,146 --> 02:08:03,676
Suppose I wanted to
implement my own RSS reader.

2998
02:08:04,056 --> 02:08:06,686
Well think back to the
format that this thing,

2999
02:08:06,686 --> 02:08:10,346
that an RSS feed has, which
again looks like this.

3000
02:08:11,186 --> 02:08:13,156
And knowing just
this, I should be able

3001
02:08:13,156 --> 02:08:15,086
to write this RSS
reader pretty easily.

3002
02:08:15,396 --> 02:08:20,446
Let me go to my RSS1.php
for a first pass at this.

3003
02:08:21,146 --> 02:08:24,536
Here as I claim a super
simple RSS reader.

3004
02:08:24,856 --> 02:08:28,856
This time, I call simple XML
load file and you can actually

3005
02:08:28,856 --> 02:08:32,426
in PHP pass URL's
generally a file is expected.

3006
02:08:32,696 --> 02:08:34,366
This has to be enabled
on a system

3007
02:08:34,366 --> 02:08:35,626
but it usually is by default.

3008
02:08:35,756 --> 02:08:38,866
But if it is a URL instead
of a file, the function,

3009
02:08:38,956 --> 02:08:41,836
simple XML load file
will use TCPIP and HTTP

3010
02:08:41,836 --> 02:08:43,946
to go get the content
and then treat it

3011
02:08:44,226 --> 02:08:45,286
as though it were a file.

3012
02:08:45,716 --> 02:08:46,926
Now here's my RSS reader.

3013
02:08:46,926 --> 02:08:51,306
For each of the item elements
that's a child of channel,

3014
02:08:51,426 --> 02:08:54,956
that's a child of the dom itself
that was returned by parsing

3015
02:08:54,956 --> 02:08:58,116
that XML file at that
URL go ahead and print

3016
02:08:58,116 --> 02:09:04,256
out an LI tag followed by an
anchor tag with this H ref.

3017
02:09:04,256 --> 02:09:05,736
Now here's slightly new syntax,

3018
02:09:05,736 --> 02:09:07,346
but you can probably
infer what's going on.

3019
02:09:07,696 --> 02:09:09,966
PHP supports variable
interpolation,

3020
02:09:10,076 --> 02:09:11,466
which means if you
have double quotes

3021
02:09:11,626 --> 02:09:14,166
and you put a PHP
variable inside of them,

3022
02:09:14,166 --> 02:09:15,966
that's variable's value
will be put there.

3023
02:09:16,546 --> 02:09:19,666
By contrast, if you use single
quotes, that will not happen.

3024
02:09:20,516 --> 02:09:23,506
However, when you have
weird syntax like arrows,

3025
02:09:23,686 --> 02:09:26,446
so it's not just dollar sign
item, you want dollar sign item,

3026
02:09:26,636 --> 02:09:30,336
arrow, link, you
need to make clearer

3027
02:09:30,336 --> 02:09:32,596
to PHP what should
be interpolated.

3028
02:09:32,696 --> 02:09:34,346
For that you use curly braces.

3029
02:09:34,726 --> 02:09:36,936
So notice I'm using double
quotes there and there,

3030
02:09:37,416 --> 02:09:39,676
but because this is kind
of a funky looking variable

3031
02:09:39,676 --> 02:09:42,566
with the arrow notation and what
not, I need to put curly braces

3032
02:09:42,566 --> 02:09:44,886
around it and those won't
show up in the output,

3033
02:09:45,016 --> 02:09:47,586
but they will tell
PHP interpolate this.

3034
02:09:47,586 --> 02:09:50,296
And to interpolate again
means replace this variable

3035
02:09:50,636 --> 02:09:52,056
with its actual value.

3036
02:09:52,466 --> 02:09:54,486
Now the fact that there are
single quotes there is just

3037
02:09:54,486 --> 02:09:55,616
a coincidence.

3038
02:09:55,956 --> 02:09:58,396
That does not mean the
variable won't be interpolated.

3039
02:09:58,396 --> 02:10:00,636
The quotes that matter
are the outer most ones

3040
02:10:00,636 --> 02:10:02,056
and in this case
they're double quotes.

3041
02:10:02,276 --> 02:10:04,176
So in PHP using double
quotes when you want

3042
02:10:04,176 --> 02:10:06,346
to put variable inside
is necessary.

3043
02:10:07,106 --> 02:10:10,016
Alright, after I've
printed out that anchor tag

3044
02:10:10,016 --> 02:10:12,566
with an [inaudible] attribute,
I just print out the title,

3045
02:10:12,796 --> 02:10:16,676
then I print out the anchor
tag, then the close LI tag.

3046
02:10:17,036 --> 02:10:19,696
And then the rest of the file
is close body, close HTML,

3047
02:10:19,866 --> 02:10:27,066
and now if I pull up RSS1.php,
which I can do here, RSS1.php,

3048
02:10:27,326 --> 02:10:29,906
we didn't look at them,

3049
02:10:29,906 --> 02:10:34,376
but there is a super simple RSS
reader for today's literally,

3050
02:10:34,376 --> 02:10:38,136
New York Times feed whereby
I just visited RSS1.php

3051
02:10:38,326 --> 02:10:40,226
on my own appliance
which is running Apache.

3052
02:10:40,536 --> 02:10:42,546
Apache has PHP support installed

3053
02:10:42,656 --> 02:10:44,426
which means there's a
PHP interpreter there.

3054
02:10:44,786 --> 02:10:48,346
The web server realizes you
want RSS1.php and says, oh,

3055
02:10:48,346 --> 02:10:51,406
let me pass this file
to PHP's interpreter

3056
02:10:51,406 --> 02:10:52,426
on the local computer.

3057
02:10:52,776 --> 02:10:55,016
The interpreter reads
my file RSS1.php,

3058
02:10:55,016 --> 02:10:56,996
top to bottom, left to right.

3059
02:10:56,996 --> 02:10:59,676
As soon as it hits the line
simple XML load file and sees

3060
02:10:59,676 --> 02:11:03,716
that URL, my appliance
makes an HTP request

3061
02:11:04,026 --> 02:11:07,746
to the New York Times.com, gets
back the XML, it gets parsed

3062
02:11:07,746 --> 02:11:09,766
by that function,
then my loop happens.

3063
02:11:09,766 --> 02:11:11,706
So all of this happens
behind the scenes in what

3064
02:11:11,706 --> 02:11:13,476
like six lines of actual code

3065
02:11:13,696 --> 02:11:16,196
and I have my own RSS
reader here spitting

3066
02:11:16,196 --> 02:11:17,956
out the titles and the links.

3067
02:11:18,616 --> 02:11:20,106
So it can be as simple as that.

3068
02:11:20,466 --> 02:11:22,096
So what's the point of
this lecture example?

3069
02:11:22,096 --> 02:11:23,906
What's the point of
this RSS example?

3070
02:11:24,156 --> 02:11:26,836
Really to give you the basic
building blocks with which

3071
02:11:26,836 --> 02:11:32,376
to create and traverse
your own menu.xml file.

3072
02:11:32,376 --> 02:11:33,636
But to do that ultimately,

3073
02:11:33,826 --> 02:11:35,056
that's just one piece
of the puzzle.

3074
02:11:35,266 --> 02:11:38,206
You'll need to have some notion
of support for sessions, right.

3075
02:11:38,206 --> 02:11:41,176
Because if the user wants
to not only see the menu,

3076
02:11:41,466 --> 02:11:44,676
but click links, or fill out
forms, adding things to his

3077
02:11:44,676 --> 02:11:46,646
or her cart, you're going to
want to remember what pizzas,

3078
02:11:46,646 --> 02:11:48,156
what salads they've
added to their cart,

3079
02:11:48,446 --> 02:11:49,976
so what super global
is appropriate there?

3080
02:11:50,516 --> 02:11:52,576
[ Inaudible ]

3081
02:11:53,076 --> 02:11:53,876
Yeah. Dollar sign,
underscore, session.

3082
02:11:53,876 --> 02:11:55,116
So you'll need to
make use of that.

3083
02:11:55,376 --> 02:11:57,436
You don't need to
use, have logins,

3084
02:11:57,496 --> 02:11:59,676
so the spec does not require
user names and passwords

3085
02:11:59,676 --> 02:12:00,286
or anything like that.

3086
02:12:00,286 --> 02:12:03,186
You don't actually need to
send the order to a company,

3087
02:12:03,186 --> 02:12:05,406
the store, you just need
to confirm for the user,

3088
02:12:05,406 --> 02:12:07,286
you could fake for the user

3089
02:12:07,366 --> 02:12:09,186
that their order has
ultimately been submitted.

3090
02:12:09,416 --> 02:12:10,656
But you're going to have
to maintain some notion

3091
02:12:10,656 --> 02:12:12,736
of a shopping cart and
enable the user to add

3092
02:12:12,986 --> 02:12:14,826
and remove things
from that cart.

3093
02:12:15,036 --> 02:12:17,886
So ultimately, you'll probably
have a few different pages

3094
02:12:18,216 --> 02:12:20,356
unless you use one
main controller

3095
02:12:20,686 --> 02:12:23,856
and have multiple views
that the controller uses.

3096
02:12:24,056 --> 02:12:25,466
But again this is the key aspect

3097
02:12:25,466 --> 02:12:27,856
of the design component
for the project.

3098
02:12:27,856 --> 02:12:29,326
There is no one right
answer here.

3099
02:12:29,526 --> 02:12:31,266
You're welcome to
bounce ideas off of us

3100
02:12:31,316 --> 02:12:33,836
on the discussion board who's
URL is in the spec and also

3101
02:12:33,836 --> 02:12:34,786
on the course's home page.

3102
02:12:35,046 --> 02:12:37,646
But there's a lot of pieces now
from lecture zero, one, two,

3103
02:12:37,646 --> 02:12:41,286
and now three that you can
hopefully start to wire together

3104
02:12:41,616 --> 02:12:45,136
in the interest of making your
own pizza ordering website

3105
02:12:45,506 --> 02:12:47,566
and along the way
hopefully you will trip

3106
02:12:47,566 --> 02:12:51,066
over a non-trivial number
of annoying data issues

3107
02:12:51,366 --> 02:12:53,046
which are going to be
representative of a class

3108
02:12:53,046 --> 02:12:54,986
of problems that are out there
in the real world when it comes

3109
02:12:54,986 --> 02:12:58,056
to just making stuff work
for companies like this one.

3110
02:12:59,316 --> 02:13:02,646
Any questions on XML,
pizza ML, or the like?

3111
02:13:02,646 --> 02:13:02,726
Yeah.

3112
02:13:02,726 --> 02:13:09,126
>> Is there any difference
between using XML

3113
02:13:09,426 --> 02:13:12,716
and PHP for [inaudible]?

3114
02:13:12,886 --> 02:13:13,786
>> Good question.

3115
02:13:13,786 --> 02:13:16,386
Is there any difference between
using PHP and XML for the menu?

3116
02:13:16,726 --> 02:13:19,946
Really, it's a separation
of data and logic.

3117
02:13:20,236 --> 02:13:23,026
In theory, you could
represent the menu somehow

3118
02:13:23,236 --> 02:13:25,556
with a whole bunch
of variables in PHP,

3119
02:13:25,556 --> 02:13:28,386
or even a massive PHP
associative array,

3120
02:13:28,616 --> 02:13:30,646
but that's not very
easy to maintain

3121
02:13:30,756 --> 02:13:34,326
and it also doesn't allow you
to semantically tag information

3122
02:13:34,446 --> 02:13:38,176
as much as you can with XML,
which again has child support,

3123
02:13:38,176 --> 02:13:41,486
which has attribute support, and
the like, and the short of it is

3124
02:13:41,486 --> 02:13:44,486
that it's just wrong to
model data in that way in PHP

3125
02:13:44,486 --> 02:13:47,236
since the data should
transcend the particular choice

3126
02:13:47,236 --> 02:13:47,846
of language.

3127
02:13:48,096 --> 02:13:49,066
So another argument in favor

3128
02:13:49,066 --> 02:13:51,536
of the XML file is now it's much
more portable, could be read

3129
02:13:51,536 --> 02:13:53,016
by different languages
and the like,

3130
02:13:53,386 --> 02:13:55,776
and so it's just a
cleaner way of doing it,

3131
02:13:55,956 --> 02:13:57,586
rather than hardcoding
things for PHP.

3132
02:13:57,586 --> 02:13:59,666
And moreover what it'll allow us

3133
02:13:59,666 --> 02:14:02,556
to do longer term is once we
introduce an actual database,

3134
02:14:02,556 --> 02:14:06,976
like MySQL, then you can leave
most of your PHP code the same

3135
02:14:07,296 --> 02:14:10,376
and just change a few lines
that relate to the XML file

3136
02:14:10,376 --> 02:14:13,066
and plugin support for
MySQL instead of XML

3137
02:14:13,306 --> 02:14:14,546
and everything just
keeps working.

3138
02:14:14,636 --> 02:14:17,446
So this separation of data
from logic allows you to sort

3139
02:14:17,446 --> 02:14:20,196
of refine and then build upon it
longer term much more cleanly.

3140
02:14:21,406 --> 02:14:22,006
Good question.

3141
02:14:22,996 --> 02:14:23,636
Any others?

3142
02:14:23,966 --> 02:14:24,186
No. Alright.

3143
02:14:25,576 --> 02:14:27,106
So that was a lot.

3144
02:14:27,106 --> 02:14:28,316
Why don't we call
it a night here?

3145
02:14:28,316 --> 02:14:29,706
I'll stick around for
one-on-one questions.

3146
02:14:29,706 --> 02:14:31,606
Peter's going to set up
and then dive into the walk

3147
02:14:31,606 --> 02:14:32,576
through of the spec itself.

3148
02:14:32,916 --> 02:14:33,916
Otherwise, I'll see
you on Wednesday.

