11<?php
2- class Countries extends Controller {
3- public function index ()
2+ class Countries extends Controller
3+ {
4+ protected $ countryModel ;
5+
6+ public function __construct ()
47 {
58 $ this ->countryModel = $ this ->model ('Country ' );
9+ }
610
11+ public function index ()
12+ {
713 $ data = $ this ->countryModel ->getCountries ();
814
915 for ($ i = 0 ; $ i < count ($ data ); $ i ++) {
@@ -13,8 +19,49 @@ public function index()
1319 }
1420
1521 $ this ->view ('countries/index ' , [
16- 'title ' => 'Home page ' ,
22+ 'title ' => 'Country page ' ,
1723 'countries ' => $ data
1824 ]);
1925 }
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+ }
2067}
0 commit comments