Advertisement
zukars3

Untitled

Apr 19th, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Controllers;
  4.  
  5. use App\Core\Database;
  6. use App\Core\View;
  7. use http\Exception\InvalidArgumentException;
  8.  
  9. require_once 'helpers.php';
  10.  
  11. class CountriesController
  12. {
  13. private $database;
  14.  
  15. public function __construct()
  16. {
  17. $this->database = database();
  18. }
  19.  
  20. public function index()
  21. {
  22. $countriesTable = $this->database->select('countries', '*');
  23.  
  24. $countriesTable = sortCountries($countriesTable, 'id');
  25.  
  26. View::show('Countries/index.php', [
  27. 'countriesTable' => $countriesTable
  28. ]);
  29. }
  30.  
  31. public function distinctCountry(array $params)
  32. {
  33. $countryTable = $this->database->select('countries', ["[>]cities" => ["country" => "country"],], ["countries.country", "cities.city"], ["countries.id" => $params['id']]);
  34.  
  35. View::show('Countries/country.php', [
  36. 'countryTable' => $countryTable
  37. ]);
  38. }
  39.  
  40. public function add(array $params)
  41. {
  42. if (isset($_POST['country']) && $_POST['country'] !== "") {
  43. $this->database->insert('countries', ['country' => $_POST['country']]);
  44. } elseif (isset($_POST['cityCountry']) && isset($_POST['city']) && $_POST['cityCountry'] !== "" && $_POST['city'] !== "") {
  45. $this->database->insert('cities', ['country' => $_POST['cityCountry'], 'city' => $_POST['city']]);
  46. } else echo "<h3>Please enter some values!</h3>";
  47.  
  48. $this->index();
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement