-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
658 lines (604 loc) · 16.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Introduction to PHP | sdphp.org</title>
<meta name="description" content="A framework for easily creating beautiful presentations using HTML">
<meta name="author" content="Hakim El Hattab">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<link href='http://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/theme/default.css">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<script>
// If the query includes 'print-pdf' we'll use the PDF print sheet
document.write( '<link rel="stylesheet" href="css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Used to fade in a background when a specific slide state is reached -->
<div class="state-background"></div>
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1>Introduction to PHP</h1>
<h3>9/27/2012</h3>
<h4 style="text-transform: none;">Slides available on sdphp.kindari.net</h4>
</section>
<section>
<h2>About me</h2>
<h3>William Cahill-Manley</h3>
<ul>
<li>Application Developer for Submodal</li>
<li>@williammanley</li>
<li>http://kindari.me</li>
<li>github.com/Kindari</li>
<li>Skype: iradnik</li>
<li>william@cahillmanley.com</l1>
</ul>
</section>
<section>
<section>
<h3>Open & Closing tags</h3>
<pre><code><title><?php echo "Hello world!"; ?></title></code></pre>
<pre><code><?php
class Foo
{
}</code></pre>
</section>
<section>
<h3>Variables</h3>
<pre><code>$title = 'Hello, world!';</code></pre>
<pre><code><title><?php echo $title; ?></title></code></pre>
<pre><title>Hello, world!</title></pre>
<p>A Variable, as the name suggests, can have its value change during the execution of a script.</p>
</section>
<section>
<h3>Constants</h3>
<pre><code>define('VERSION', '1.2.3');</code></pre>
<pre><code>echo "Version: " . VERSION;</code></pre>
<pre>Version: 1.2.3</pre>
<p>A constant, once defined, cannot be changed or unset. Traditionally constants are uppercase.</p>
</section>
<section>
<h3>Including other scripts</h3>
<pre><code>// foobar.php
$name = 'William';</code></pre>
<pre><code>// baz.php
include 'foobar.php';
echo $name;</code></pre>
<pre>William</pre>
<pre><code>require 'test.php';</code></pre>
<pre>Warning: require(test.php): failed to open stream: No such file or directory on line 1
Fatal error: require(): Failed opening required 'test.php' (include_path='.:/usr/lib/php') on line 1</pre>
</section>
<section>
<h3>Include file.. once</h3>
<pre><code>// test.php
echo "Test\n";</code></pre>
<pre><code> // test2.php
include_once 'test.php';
require_once 'test.php';
include_once 'test.php';
require_once 'test.php';</code></pre>
<pre>Test</pre>
<pre><code> // test3.php
include 'test.php';
require 'test.php';
include 'test.php';
require 'test.php';</code></pre>
<pre>Test
Test
Test
Test</pre>
<p>Useful for class and function loading</p>
</section>
</section>
<section>
<section>
<h2>Types in PHP</h2>
<ul>
<li>Strings</li>
<li>Integers</li>
<li>Floats</li>
<li>Arrays</li>
<li>and many more...</li>
</ul>
</section>
<section>
<h3>Strings</h3>
<pre><code>$foo = 'bar';</code></pre>
<pre><code>$bar = "baz";</code></pre>
<p class="fragment">Whats the difference?</p>
<pre class="fragment"><code>$foo = 'ba\tr'; # equal to 'ba\tr'</code></pre>
<pre class="fragment"><code>$bar = "ba\tz"; # equal to 'ba z'</code></pre>
</section>
<section>
<h3>Integers</h3>
<pre><code>$a = 1234; // decimal number</code></pre>
<pre><code>$b = -123; // a negative number</code></pre>
<pre class="fragment"><code>$c = 0123; // octal number (equivalent to 83 decimal)</code></pre>
<pre class="fragment"><code>$d = 0x1A; // hexadecimal number (equivalent to 26 decimal)</code></pre>
</section>
<section>
<h3>Arrays</h3>
<pre><code>$people = array('Eric', 'John', 'William');</code></pre>
<pre class="fragment"><code>echo $people[1];</code></pre>
<pre class="fragment">John</pre>
<div class="fragment">
<p>Arrays are zero-based.</p>
<pre><code>echo $people[0];</code></pre>
<pre>Eric</pre>
</div>
<div class="fragment">
<p>Arrays can be of mixed types</p>
<pre><code>$numbers = array(4, 'Eight', 15, 16, 'Twenty Three', array(42));</code></pre>
</div>
</section>
<section>
<h3>Associative Arrays</h3>
<p>Key => Value pairs of data</p>
<pre><code>$person = array(
'firstname' => 'William',
'lastname' => 'Cahill-Manley',
);</code></pre>
<pre class="fragment"><code>echo $person['firstname'];</code></pre>
<pre class="fragment">William</pre>
</section>
</section>
<section>
<section>
<h3>Flow Control</h3>
<pre><code>if ($_GET['number'] > 5)
{
echo "Hooray!";
}
elseif ( $_GET['number'] == 5)
{
echo "Indifferent";
}
else
{
echo "Boo :/";
}</pre></code>
<h4><A href="example_1.php?number=10">Example</a></h4>
</section>
<section>
<h3>For Loops</h3>
<pre><code>for( expr1; expr2; expr3 ) {}</code></pre>
<pre class="fragment"><code>for( $i = 0; $i < 10; $i++)
{
echo "{$i}\n";
}</code></pre>
<pre class="fragment">
0
1
2
3
4
5
6
7
8
9</pre>
</section>
<section>
<h3>Foreach loops</h3>
<pre><code>$people = array(
'Eric' => 'Blue',
'John' => 'Pink',
'William' => 'Green'
);</code></pre>
<pre class="fragment"><code>foreach($people as $person => $color)
{
echo "{$person}'s favorite color is {$color}\n";
}</code></pre>
<pre class="fragment">Eric's favorite color is Blue
John's favorite color is Pink
William's favorite color is Green</pre>
</section>
<section>
<h3>Foreach loops</h3>
<pre><code>$people = array(
'Eric' => 'Blue',
'John' => 'Pink',
'William' => 'Green'
);</code></pre>
<pre class="fragment"><code>foreach($people as $color)
{
echo "{$color}\n";
}</code></pre>
<pre class="fragment">Blue
Pink
Green</pre>
</section>
<section>
<h3>Foreach loops</h3>
<pre><code>$people = array( 'Eric', 'John', 'William' );</code></pre>
<pre class="fragment"><code>foreach($people as $key =>$person)
{
echo "Hello {$person}! {$key}\n";
}</code></pre>
<pre class="fragment">
Hello Eric! 0
Hello John! 1
Hello William! 2
</pre>
</section>
<section>
<h3>While loops</h3>
<pre><code>$i = 0;
while ( $i < 10 )
{
echo "{$i}\n";
$i++;
}</code></pre>
<pre>0
1
2
3
4
5
6
7
8
9</pre>
</section>
<section>
<h3>Do While</h3>
<pre><code>$something = False;
while($something) echo "while wont execute\n";
do
echo "do while will always execute once\n";
while ($something);</code></pre>
<pre>do while will always execute once</pre>
</section>
<section>
<h3>Switch Cases</h3>
<pre><code>$person = $_GET['person'];
switch($person)
{
case 'John':
echo 'Hey John!';
case 'Eric':
echo 'Hey Eric!';
break;
case 'William':
echo 'I for one welcome our new overlord';
break;
default:
echo "Hello, {$person}!";
}</code></pre>
<a href="example_2.php?person=William">Example</a>
</section>
<section>
<h3>continue and break</h3>
<pre><code>
foreach( array(1,2,3,4,5) as $num)
{
if ($num==2) continue;
if ($num==5) break;
echo "{$num}\n";
}</code></pre>
<pre class="fragment">1
3
4</pre>
<ul>
<li class="fragment">for</li>
<li class="fragment">foreach</li>
<li class="fragment">while</li>
<li class="fragment">do ... while</li>
<li class="fragment">switch</li>
</ul>
</section>
</section>
<section>
<section>
<h3>Alternate Syntaxes</h3>
<pre><code><?="test"?></code></pre>
<pre><code><?php echo "test"; ?></code></pre>
<pre>test</pre>
</section>
<section>
<h3>Alternate Syntax: if</h3>
<pre><code>if ($something):
echo "Something";
endif;</code></pre>
</section>
<section>
<h3>Alternate Syntax: for</h3>
<pre><code>for ($i = 0; $i < 5; $i++):
echo "Something";
endfor;</code></pre>
</section>
<section>
<h3>Alternate Syntax: foreach</h3>
<pre><code>foreach ($foo as $bar):
echo "Baz";
endforeach;</code></pre>
</section>
<section>
<h3>Alternate Syntax: while</h3>
<pre><code>while ($something):
echo "Something";
endwhile;</code></pre>
</section>
</section>
<section>
<section>
<h3>Functions</h3>
<pre><code>function add( $a, $b ) {
$sum = $a + $b;
return "{$a} + {$b} = {$sum}";
echo "Hello, world!";
}
echo add(4, 7);</code></pre>
<pre>4 + 7 = 11</pre>
</section>
<section>
<h3>Classes</h3>
<pre><code>class Person {
private $firstname = '';
private $lastname = '';
public function __construct( $firstname, $lastname ) {
$this->firstname = $firstname;
$this->lastname = $lastname;
}
public function fullname() {
return "{$this->firstname} {$this->lastname}";
}
}
$william = new Person('William', 'Cahill-Manley');
echo $william->fullname();</code></pre>
<pre>William Cahill-Manley</pre>
</section>
<section>
<h3>Magic: Get</h3>
<pre><code>class Foo {
public $bar = 'baz';
public function __get($key) {
return "No {$key} here ;(\n";
}
}
$foo = new Foo();
echo $foo->baz;
echo $foo->bar;</code></pre>
<pre>No baz here ;(
baz</pre>
</section>
<section>
<h3>Magic: Get</h3>
<pre><code>class Foo {
public $bar = 'baz';
protected function __get($key) {
return "No {$key} here ;(\n";
}
}
$foo = new Foo();
echo $foo->baz;
echo $foo->bar;</code></pre>
<pre>
Warning: The magic method __get() must have public visibility and cannot be static
No baz here ;(
Warning: The magic method __get() must have public visibility and cannot be static
baz</pre>
</section>
<section>
<h3>Magic: Set</h3>
<pre><code>class Foo {
public $data = array();
public function __set($key, $value) {
$this->data[$key] = $value;
echo "Added key '{$key}' with value '{$value}'\n";
}
}
$foo = new Foo();
$foo->name = 'William';
$foo->bar = 'baz';
</code></pre>
<pre>Added key 'name' with value 'William'
Added key 'bar' with value 'baz'</pre>
</section>
<section>
<h3>Static</h3>
<pre><code>class Person {
public static $instances = array();
public function __construct( $name ) {
static::$instances[] = $this;
$this->name = $name;
}
public static function all() {
$output = array();
foreach(static::$instances as $person) {
$output[] = $person->name;
}
return $output;
}
}
$william = new Person('William');
$john = new Person('John');
$eric = new Person('Eric');
var_dump( Person::all() );
</code></pre>
<pre>array(3) {
[0]=> string(7) "William"
[1]=> string(4) "John"
[2]=> string(4) "Eric"
}</pre>
</section>
<section>
<h3>Class Constants</h3>
<pre><code>class Api {
const SOME_ENDPOINT = 'http://cahillmanley.com/ip.json';
}
echo Api::SOME_ENDPOINT;</code></pre>
<pre>http://cahillmanley.com/ip.json</pre>
</section>
<section>
<h3>Class Visibility</h3>
<pre><code>
class P {
private $private = 'Foo\n';
protected $protected = 'Bar\n';
public $public = 'Baz\n';
public function __construct() {
echo $this->private;
}
}
class C extends P{
public function __construct() {
echo $this->protected;
}
}
$p = new P();
$c = new C();
echo $p->public;</code></pre>
<pre>Foo
Bar
Baz</pre>
</section>
<section>
<h3>Method Overloading</h3>
<pre><code>
class Something {
public function __call($name,$arguments) {
$args = implode(',', $arguments);
return "Something->{$name}({$args})\n";
}
public static function __callStatic($name,$arguments) {
$args = implode(',', $arguments);
return "Something::{$name}({$args})\n";
}
}
$s = new Something();
echo $s->test(1,2,3);
echo $s::test(4,5,6);</code></pre>
<pre>Something->test(1,2,3)
Something::test(4,5,6)</pre>
</section>
</section>
<section>
<h3>Database Access</h3>
<a href="http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/">Why you should be using PDO</a>
<ul>
<li>Cross Database Driver support</li>
<li>Prepared Statements</li>
<li>Proper bindings</li>
<li>and lots lots more</li>
</ul>
</section>
<section>
<section>
<h3>Models, Views, Controllers</h3>
<ul>
<li>Code Seperation</li>
<li>Reusability</li>
<li>Ease Refactoring</li>
</ul>
</section>
<section>
<h3>Models</h3>
<pre><code>class People {
public static function all() {
return array( 'William', 'John', Eric' );
}
}</code></pre>
<ul><li class="fragment">a model represents your data</li>
<li class="fragment">Logical container for<ul>
<li class="fragment">Database calls</li>
<li class="fragment">API Access</li>
</ul></li>
<li class="fragment">Models usually represent<ul>
<li class="fragment">Tables in a database</li>
<li class="fragment">a file or collection of files on a hard drive</li>
<li class="fragment">Documents stored in Mongo</li>
<li class="fragment">Any other data containers you need to define</li>
</ul></li>
</ul> </section>
<section>
<h3>Views</h3>
<pre><code><h1>People</h1>
<ul>
<?php foreach($people as $person): ?>
<li><?=$person?></li>
<?php endforeach; ?>
</ul></code></pre>
</section>
<section>
<h3>View.. Models?</h3>
<pre><code>class View {
private $data = array();
public $path = '';
public function __construct($path) {
$this->path = $path;
}
public function render() {
extract($this->data);
ob_start();
require $this->path;
return ob_get_clean();
}
public function __set($key, $value) {
$this->data[ $key ] = $value;
}
}</code></pre>
</section>
<section>
<h3>Controllers</h3>
<pre><code>class People_Controller {
public function index() {
$view = new View('people.php');
$view->people = People::all();
return $view->render();
}
}
$controller = new People_Controller();
echo $controller->index();</code></pre>
<pre><h1>People</h1>
<ul>
<li>William</li>
<li>John</li>
<li>Eric</li>
</ul></pre>
</section>
</section>
</div>
<!-- The navigational controls UI -->
<aside class="controls">
<a class="left" href="#">◄</a>
<a class="right" href="#">►</a>
<a class="up" href="#">▲</a>
<a class="down" href="#">▼</a>
</aside>
<!-- Presentation progress bar -->
<div class="progress"><span></span></div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/linear(2d)
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'lib/js/highlight.js', async: true, callback: function() { window.hljs.initHighlightingOnLoad(); } },
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'lib/js/showdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'lib/js/data-markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'socket.io/socket.io.js', async: true, condition: function() { return window.location.host === 'localhost:1947'; } },
{ src: 'plugin/speakernotes/client.js', async: true, condition: function() { return window.location.host === 'localhost:1947'; } },
]
});
</script>
</body>
</html>