0
내가 객체를 생성 한 메서드를 호출 한어떻게 값을 함수로 반환 할 수 있습니까? 내 등록 페이지에서
$getValidations = new Validation();
$error = $getValidations->getValues($postData);
지금 내 검증 클래스는 다음과 같습니다
class Validation {
public function getValues($postData) {
$f_name = (isset($postData['f_name']) && ($postData['f_name'])) ? htmlspecialchars(trim($postData['f_name'])) : NULL;
$l_name = (isset($postData['l_name']) && ($postData['l_name'])) ? htmlspecialchars(trim($postData['l_name'])) : NULL;
$this->addFields($f_name, 'req', 'First Name is required. ');
$this->addFields($l_name, 'req', 'Last Name is required. ');
$error = $this->validate();
print_r($error);
return $error;
}
function addFields($postVar, $authType, $error) {
$index = $this->id++;
$this->check_vars[$index]['data'] = $postVar;
$this->check_vars[$index]['authtype'] = $authType;
$this->check_vars[$index]['error'] = $error;
}
function validate() {
... validations rules
return $erromsg;
}
이제 문제는 다음과 같습니다
$error = $this->validate();
print_r($error);
return $error;
가 작동하지 않습니다 . 은 $this->
이 맞나요?
$erromsg
오류 메시지를 받으려면 어떻게해야합니까?
validate()는 무엇인가를 반환합니까? 그 함수에 $ erromsg이 설정되어 있는지 확인하십시오. –
yaa validate가 오류 메시지를 반환하는 경우 .... – Sparkx
그 코드가 제게 좋을 것 같습니다. 작동하지 않는 예제를 게시 할 수 있습니까? –