如何返回值才能起作用?

时间:2011-10-20 09:35:11

标签: php class

从我的注册页面我创建了一个对象并调用了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错误消息?

1 个答案:

答案 0 :(得分:1)

验证方法内部有问题。尝试测试验证方法:

function validate() {
  echo "I have been called";
  // ... validations rules
  echo "Error: $erromsg";
  return $erromsg;
}
  • 是否打电话?
  • 这个方法里面发生了什么?