开发者

How should Zend_Validator_StringLength extended?

How should Zend_Validator_StringLength extended?

MyValidator:

class Zend_Validate_StringLengthNoTags extends Zend_Validate_StringLength {

    public function  __construct($options = array()) {
        parent::__construct($options);
    }

    public function isValid($value) {
        return parent::isValid(trim(strip_tags($value)));
    }
}

Use of validator - bug not assign values to $this->_min, $this->_max:

$text->addValidator(new Zend_Validator_StringLengthNoTags(array('max'=>4,'min'=>2)));

Edit:

root of bug: $this->_min==1, $this->_max==null , but it should be

$this->_min==2, $this->_max==4

Update: the answer: This was internal application system problem that generate this bug, it fixed soo the code abov开发者_JAVA百科e working. Thanks for all peaple they try to help me.

Thanks


It seems that your Zend_Validate_StringLengthNoTags could be replaced simply by filters StripTags and StringTrim and standard Zend_Validate_StringLength validator.

For example, I think that the following would work the same as your validator:

   $text->setFilters(array('stripTags','stringTrim'));
   $text->addValidator(new Zend_Validator_StringLength(array('max'=>4,'min'=>2)));

The reason is that validation in Zend Framework is performed after filtering, i.e. on filtered data.

Returning to your Zend_Validate_StringLengthNoTags code. The code looks ok and I cannot spote a problem with it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜