Listing Tours
Let's create a list of tours to show to the user.
We'll cover the following...
We'll cover the following...
Creating a new script to list tours
We start by creating another page script: pages/list-tours.php.
To make it accessible for users, we have to define a route for it in index.php:
$urlMap = ['/create-tour' => 'create-tour.php','/list-tours' => 'list-tours.php',// ...];
In list-tours.php, we put the usual stuff:
<?phpinclude(__DIR__ . '/../bootstrap.php');include(__DIR__ . '/../_header.php');include(__DIR__ . '/../_footer.php');
Loading the tour data
Between the bootstrap phase and showing the header of the page, we should do some work. Load all the tour data from the tours.json file.
For starters, let’s just copy the code that does this from create-tour.php and paste it in list-tours.php:
<?phpinclude(__DIR__ . '/../bootstrap.php');$toursJsonFile = __DIR__ . '/../data/tours.json';if (file_exists($toursJsonFile)) {$jsonData = file_get_contents($toursJsonFile);$toursData = json_decode($jsonData, true);} else {$toursData = [];}include(__DIR__ . '/../_header.php');include(__DIR__ . '/../_footer.php');