0
iは、オブジェクトを作成し、1つのメソッドを呼び出しているどのように機能に値を返すことができますか?私の登録ページから
$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
そのコードは私には良いようですが、動作していないサンプルを投稿できますか? –