Php 如何不两次接收同一验证消息-Yii规则
我最近使用Yii规则实现了自己的错误函数。在功能中,我正在检查给定的电话号码和pin是否与我想要的电话号码和pin完全相同。(我需要pin码和电话号码,因为我将同时检查它们在另一台服务器上是否有效)。然而,现在每当我输入错误时,我都会收到两次手动输入的错误。 这是自定义规则的代码Php 如何不两次接收同一验证消息-Yii规则,php,yii,yii-validation,Php,Yii,Yii Validation,我最近使用Yii规则实现了自己的错误函数。在功能中,我正在检查给定的电话号码和pin是否与我想要的电话号码和pin完全相同。(我需要pin码和电话号码,因为我将同时检查它们在另一台服务器上是否有效)。然而,现在每当我输入错误时,我都会收到两次手动输入的错误。 这是自定义规则的代码 /** * * this function checks whether the given msisdn and pin number create a valid tigo cash account * @p
/**
*
* 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码组合无效”错误两次。我想这与我分别传递msisdn和pin有关-有没有办法让程序只显示一次错误 我认为您的规则不正确,因为您需要将数组插入引号中
public function rules()
{
return array(
array("array('msisdn', 'pin')", 'tigoValidate')
);
}