Saving JSON-Encoded Data in a File
In this lesson, we will combine all of the previously-discussed techniques by creating something many applications have: a CRUD interface.
Developing travel agency website
CRUD stands for “Create - Read - Update - Delete”. Although at some point you will come across people who don’t like it at all, CRUD can be a powerful way of looking at your application’s abilities.
In the following sections, we are going to expand our online business. We will become a serious travel agency that offers tours from Amsterdam to all kinds of interesting cities nearby. The first thing our business needs is to show a list of all the available tours. Also, since we think traveling should be for everyone, we will take special care to make most of our tours accessible.
Efficacy of CRUD
Before we can show a list of tours on the website, we first have to define them somewhere. We could hard-code them as an array:
$tours = [['destination' => 'Berlin','number_of_tickets_available' => 10,'is_accessible' => true],// and so on...];
If we do this, we would have to redeploy the website every time we wanted to add a new tour, edit an existing one, or remove one. This is where CRUD comes in: we want to let the user make all of these changes on the website itself.
-
A user who is logged in and is known to be an administrator should have the ability to edit a tour, add a new one, or delete one.
-
Normal users should be able to ...