gpt4 book ai didi

php - symfony 中的自定义验证器

转载 作者:搜寻专家 更新时间:2023-10-31 20:51:48 24 4
gpt4 key购买 nike

我想为 Symfony 1.4 创建自定义验证器,例如检查长度名称。我知道它存在,但我想要拥有它。

我创建/myapp/lib/validator/sfValidatorName.class.php

必须存在:

class sfValidatorName extends sfValidatorBase
{

protected function configure($options = array(),
$messages = array()) {

$this->addMessage('invalid', 'Invalid name!');
}

protected function doClean($value) {

}
}

以及我如何为此添加我的功能,例如:

    if (count($letters) < 3) {
return 'too small';
} else if (count($letters) > 43) {
return 'too long';
}

最佳答案

  1. 打开/lib/validator/sfValidatorString.class.php
  2. 在该验证器之后为您的验证器建模。

关于php - symfony 中的自定义验证器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6694334/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com