7. Data Persistence
Activity 7.1: Contact Management Application
Solution
Let's discuss the new or changed items, from the most uncoupled ones to the most complex ones.
A good start here is the User
model class since this class will be invoked on every page for authenticated users; let's put this file inside the src/models/
directory:
- Create the
src/models/User.php
file and add the following content. - After declaring the namespace and imports (the
use
keyword), we define the properties of theUser
class, giving names similar to the column names of theusers
table from the database:<?php declare(strict_types=1); namespace Models; use DateTime; class User { /** @var int */ private $id; /** @var string */ private $username; /** @var string */ private $password; /** @var DateTime */ ...