1
1
<?php
2
- class Countries extends Controller {
3
- public function index ()
2
+ class Countries extends Controller
3
+ {
4
+ protected $ countryModel ;
5
+
6
+ public function __construct ()
4
7
{
5
8
$ this ->countryModel = $ this ->model ('Country ' );
9
+ }
6
10
11
+ public function index ()
12
+ {
7
13
$ data = $ this ->countryModel ->getCountries ();
8
14
9
15
for ($ i = 0 ; $ i < count ($ data ); $ i ++) {
@@ -13,8 +19,49 @@ public function index()
13
19
}
14
20
15
21
$ this ->view ('countries/index ' , [
16
- 'title ' => 'Home page ' ,
22
+ 'title ' => 'Country page ' ,
17
23
'countries ' => $ data
18
24
]);
19
25
}
26
+
27
+ public function edit ()
28
+ {
29
+ $ id = $ _GET ["id " ];
30
+
31
+ if (!isset ($ id )) {
32
+ header ('Location: ../countries ' );
33
+ }
34
+
35
+ $ this ->view ('countries/edit ' , [
36
+ 'title ' => 'Edit Country page ' ,
37
+ 'continents ' => $ this ->countryModel ->getContinents (),
38
+ 'country ' => $ this ->countryModel ->getCountry ($ id )
39
+ ]);
40
+ }
41
+
42
+ public function applyChanges ()
43
+ {
44
+ $ this ->countryModel ->editCountry (
45
+ intval ($ _POST ["id " ]),
46
+ $ _POST ["name " ],
47
+ $ _POST ["capitalCity " ],
48
+ $ _POST ["continent " ],
49
+ intval ($ _POST ["population " ])
50
+ );
51
+
52
+ header ('Location: ../countries ' );
53
+ }
54
+
55
+ public function delete ()
56
+ {
57
+ $ id = $ _GET ["id " ];
58
+
59
+ if (!isset ($ id )) {
60
+ header ('Location: ../countries ' );
61
+ }
62
+
63
+ $ this ->countryModel ->deleteCountry ($ id );
64
+
65
+ header ('Location: ../countries ' );
66
+ }
20
67
}
0 commit comments