这是附加的代码。 如果缺少任何属性,如何抛出错误消息? 我需要检查所有属性是否来自表单。如果缺少任何属性,我想抛出一条包含正确错误代码的错误消息。
$get_email = Null;
$get_password = Null;
$get_username = Null;
if (isset($_POST['username']) ) {
$get_username = $_POST['username'];
}
if (isset($_POST['email']) && isset($_POST['password']) ) {
$get_email = $_POST['email'];
$get_password = $_POST['password'];
}
if ($get_email == Null || $get_username == Null || $get_password == Null ) {
// through error code with message
}
else {
$model = new SignupForm();
$model->email = $get_email;
$model->username = $get_username;
$model->password = $get_password;
}
答案 0 :(得分:0)
以下是我实现目标的代码。
$ model = new SignupForm;
if (isset($_POST['username'] )) {
$model->username = $_POST['username'];
}
if (isset($_POST['email'] )) {
$model->email = $_POST['email'];
}
if (isset($_POST['password'] )) {
$model->password = $_POST['password'];
}
if($model->validate()){
$model->signup();
}
else{
return $model->getErrors();
}