2011-10-20 7 views
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エラーメッセージを受け取るにはどうすればよいですか?

+0

validate()は何かを返しますか?その関数に$ erromsgが設定されていますか? –

+0

yaa validateがエラーメッセージを返す場合は.... – Sparkx

+0

そのコードは私には良いようですが、動作していないサンプルを投稿できますか? –

答えて

1

メソッドの検証に問題があります。テストvalidateメソッドを試してみてください。それは

function validate() { 
    echo "I have been called"; 
    // ... validations rules 
    echo "Error: $erromsg"; 
    return $erromsg; 
} 
  • 呼ばれていますか?
  • このメソッドの内部ではどうなりましたか?