2014-07-22 18 views
0

我最近使用Yii規則實現了我自己的錯誤函數。在功能內,我正在檢查給定的電話號碼和引腳是否是確切的電話號碼和我想要的引腳。 (我需要將引腳和電話號碼放在一起,因爲我將檢查它們在一起是否在另一臺服務器上有效)。但是,現在每當輸入錯誤時,我都會收到我手動輸入的錯誤兩次。 下面是自定義規則如何不接收相同的驗證信息兩次 - 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碼數組合不起作用'錯誤兩次,我認爲這與我通過msisdn和別針分開 - 有什麼辦法可以讓我的程序只顯示一次錯誤嗎?

回答

1

我認爲你的規則不正確因爲你需要將數組插入到q中uotes

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

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