// Controller if ($_SERVER['REQUEST_METHOD'] == 'POST') { $name = $_POST['name']; $email = $_POST['email']; // Validate data if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { // Display error message to the user } else { $user = new User(); $user->name = $name; $user->email = $email; $user->save(); // Render success view include 'views/success.php'; } } // Model (User class) class User { public $name; public $email; public function save() { // Save the User to the database } } // View (success.php)Success!
Your data has been saved.
// Controller $contacts = Contact::getAll(); // Render view include 'views/contacts.php'; // Model (Contact class) class Contact { public $name; public $email; public static function getAll() { // Retrieve contacts from the database $contacts = array(); // Populate $contacts array with data return $contacts; } } // View (contacts.php)Contacts