开发者

Zend_Validate's isValid() method, and the $_POST array

In a book on the Zend Framework I have come across a custom validator for unique email addresses. The validator extends Zend_Validate_Abstra开发者_如何学Goct and therefore implements the isValid() interface.

In the interface the method signature is isValid($value). In the concrete class, it's isValid($value, $context = null).

The author explains that the $context variable contains the $_POST array and he relies on values from the array in the method's implementation. When I try to reproduce the code, however, my $context array is null. Furthermore, I am unable to find any reference to $context in the Zend_Validation reference guide, or to passing in the $_POST values.

Has anyone else come across this?

BTW, the book is Zend Framework 1.8 Web Application Development by Keith Pope.

Thanks!


The $context array is passed when used with Zend_Form_Element::isValid method

Here is the snippet from Zend_Form_Element::isValid that is passing the $_POST as $context which is normally received from Zend_Form::isValid

            foreach ($value as $val) {
                if (!$validator->isValid($val, $context)) {
                    $result = false;
                    if ($this->_hasErrorMessages()) {
                        $messages = $this->_getErrorMessages();
                        $errors   = $messages;
                    } else {
                        $messages = array_merge($messages, $validator->getMessages());
                        $errors   = array_merge($errors,   $validator->getErrors());
                    }
                }
            }


It looks like the documentation for Zend_Validate is incomplete.

This behavior is described in the manual for Zend_Form_Element (ctl-f "Validation Context")

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜