这是我UsersController
在 PHP 中进行验证的地方,我已经在 index 中开始了会话,但我不确定在哪里结束它以及如何结束它:
<?php
public function createAction(){
require "Views/Users/new.php";
if (empty($_POST["email"])) {
$validation = false;
array_push($errors, "Field 'email' is required.");
}elseif (!filter_var($_POST["email"],FILTER_VALIDATE_EMAIL))
{
$validation = false;
array_push($errors, "Field'email' invalid format.");
}
if ($validation) {
$user = new Users();
$user->email = $_POST["email"];
$status = Users::insert($user);
}
if ($validation) {
$_SESSION["users-create-errors"] = $errors;
if (array_key_exists("users-create-errors", $_SESSION))
{
unset($_SESSION["users-create-errors"]);
}
}
}
}
}