0
我被困在這..我們說,我有string1 &字符串2(在同一模型中),其中string1有7位數字和string2的2位數字。 然後我想匹配它們在一起,其中string1的開始數字中的2必須與string2相同。我想在這個模型代碼>>如何在Yii中匹配字符串?
public function CekDigit($attribute,$params)
{
$attribute=substr($this->string1,0,-7);
$params=$this->string2;
if($this->$attribute==$params['subject'])
{
$this->addError(‘Error’, $params['message']);
return false;
}
}
而在規則,我把這個代碼>>
<?php
array('string1','cekdigit','message'=>'the code is unmatched','subject'),
?>
之後我做了代碼,我試圖填補$字符串1與23xxxxxxx ,但我得到一個錯誤,即CException:屬性model.23未定義。任何人都可以幫我嗎?非常感謝
可以打印$ _ POST內CekDigit()和複製粘貼的結果。 – rajmohan 2012-03-02 04:58:21
我不認爲你知道那裏發生了什麼...請仔細閱讀這個 - http://www.yiiframework.com/wiki/168/create-your-own-validation-rule/ – 2012-03-02 05:49:32
看起來像你的'在某個階段重新調用'$ string1'作爲'$$ string1'。另外,看起來你將'$ params'設置爲一個字符串('$ params = $ this-> string2'),但是你試圖與一個數組值相比較('$ params ['subject']' ) – Avanche 2012-03-02 09:43:47