Introducing Some Reusable Elements
Learn how to make the code reusable.
We'll cover the following...
Steps to create the edit tour script
The edit-tour.php
script can make use of the id
query parameter to determine which tour should be edited.
This query parameter will be available as $_GET['id']
.
With this information, we can take the following steps:
- Load the data for the tour with the given ID.
- Show the data in the form.
- When the user has submitted the form, we normalize the data, validate it, and then save the updated data.
Creating reusable snippets
Most of the steps are pretty similar to what we did in create-tour.php
.
We can copy the code from that script to edit-tour.php
, or we can do the right thing and make the code actually reusable.
Let’s introduce the following:
- A snippet for showing the
Access this course and 1400+ top-rated courses and projects.