Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Controllers;
- use App\Core\Database;
- use App\Core\View;
- use http\Exception\InvalidArgumentException;
- require_once 'helpers.php';
- class CountriesController
- {
- private $database;
- public function __construct()
- {
- $this->database = database();
- }
- public function index()
- {
- $countriesTable = $this->database->select('countries', '*');
- $countriesTable = sortCountries($countriesTable, 'id');
- View::show('Countries/index.php', [
- 'countriesTable' => $countriesTable
- ]);
- }
- public function distinctCountry(array $params)
- {
- $countryTable = $this->database->select('countries', ["[>]cities" => ["country" => "country"],], ["countries.country", "cities.city"], ["countries.id" => $params['id']]);
- View::show('Countries/country.php', [
- 'countryTable' => $countryTable
- ]);
- }
- public function add(array $params)
- {
- if (isset($_POST['country']) && $_POST['country'] !== "") {
- $this->database->insert('countries', ['country' => $_POST['country']]);
- } elseif (isset($_POST['cityCountry']) && isset($_POST['city']) && $_POST['cityCountry'] !== "" && $_POST['city'] !== "") {
- $this->database->insert('cities', ['country' => $_POST['cityCountry'], 'city' => $_POST['city']]);
- } else echo "<h3>Please enter some values!</h3>";
- $this->index();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement