0

我有一个 Zend 表单密码自定义验证。

我已将addValidator函数IInd参数设置为 false,因为我需要一次获取所有错误。我的两个验证类都设置了self::INVLID相应的错误消息。

但是当我查看 Zend 控制器时,即使两个验证都失败了,我也只收到一个(最后一个)错误消息。

我需要一次所有的错误信息。

    /* Form validation*/
    $passwordSpecialValidator = new Passwordspecialvalidationvalidator();
    $passwordHistoryValidator = new Passwordhistorylvalidationvalidator(new model(), $username, $newpass);

    $this->newpass->addValidator($passwordSpecialValidator, false)
            ->addValidator($passwordHistoryValidator, false);

    /* One validation class */

    class Passwordhistorylvalidationvalidator extends Zend_Validate_Abstract {

        const INVLID = '';

        protected $_messageTemplates = array(
            self::INVLID => 'Your password doesnt meet the history requirements'
        );

        public function __construct($model, $username, $password) {
            $this->_model = $model;
            $this->_username = $username;
            $this->_password = $password;
        }

        public function isValid($value, $context = null) {

            if ($this->_username == "") {
                $auth = Zend_Auth::getInstance();
                if ($auth->hasIdentity()) {
                    $arrayResult = $auth->getIdentity();
                    if (isset($arrayResult->username)) {
                        $this->_username = $arrayResult->username;
                    }
                }
            }
            $passwordExists = false;
            $oldPasswords = $this->_model->getHistoryPasswords($this->_username, $this->_password);

            if (count($oldPasswords) > 0) {
                $passwordExists = true;
            }

            if ($passwordExists == false) {
                return true;
            } else {
                $this->_setValue($value);
                $this->_error(self::INVLID);
                return false;
            }
        }


    }
    /* Getting error messages */
    foreach ($objForm->getMessages() as $messages) {
        foreach ($messages as $message) {
            $errMessages[] = $message;
        }
    }

$errMessages但是即使特殊验证和历史验证都失败了,该数组也只有最后一条验证消息(没有索引)。如果两个验证都失败,我将如何在数组中获取两个错误消息?

4

0 回答 0