【问题标题】:How to not receive the same validation message twice - Yii Rules如何两次没有收到相同的验证消息 - Yii 规则
【发布时间】:2014-07-22 10:31:28
【问题描述】:

我最近使用 Yii 规则实现了我自己的错误函数。在该功能中,我正在检查给定的电话号码和密码是否是我想要的确切电话号码和密码。 (我需要将密码和电话号码放在一起,因为我将一起检查它们在另一台服务器上是否有效)。但是,现在每当我输入错误的内容时,我都会收到两次手动输入的错误。 这是自定义规则的代码

/** 
*  
* this function checks whether the given msisdn and pin number create a valid tigo cash account
* @param $array that takes in two arguments, the first argument is the msisdn, and the second 
* is the pin 
* @return returns an error if the pin and msisdn do not validate with the Tigo server 
*/ 
public function tigoValidate($array)
{   
    // clarify the origins of the variable 
    $msisdn = $array[0];
    $pin = $array[1];
    // if the pin does not equal this and the pin does not equal that 
    if($array[0] !== '250728424547' && $array[1] !== '1463')
    {
        $this->addError($array, 'your number-pin combination does not work!');      
    }

}

这就是我在规则中的称呼

public function rules()
{
    return array(
        array(array('msisdn', 'pin'), 'tigoValidate')
    );
}

当输入错误的 msisdn 或 pin 时,我会两次返回“您的 pin-number 组合不起作用”错误。我认为这与我分别传递 msisdn 和 pin 有关 - 有什么办法只能程序是否显示一次错误?

【问题讨论】:

    标签: php yii yii-validation


    【解决方案1】:

    我认为您的规则不正确,因为您需要将数组插入引号

    public function rules()
    {
        return array(
            array("array('msisdn', 'pin')", 'tigoValidate')
        );
    }
    

    http://www.yiiframework.com/wiki/56/#hh0

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-10
      • 2021-05-26
      • 1970-01-01
      • 2010-10-30
      • 2017-02-06
      • 1970-01-01
      相关资源
      最近更新 更多