嗨我試圖做我自己的形式驗證器就像在默認配置生成的LoginForm
authenticate
方法。爲什麼Yii驗證器不能工作?
public function rules()
{
return array(
// username and password are required
array('mnemonic, target_reg, source_reg', 'required'),
// rememberMe needs to be a boolean
array('target_reg_indirection, source_reg_indirection', 'boolean'),
array('mnemonic','foo'),
);
}
,這裏是驗證方法:
public function foo($attribute,$params){
$this->addError('mnemonic', 'there was an error, you foo!');
}
它只是不工作對我來說...注意我是如何增加一個規則,不應該工作每次。我只是做了它,所以我可以看到它是如何工作的。但在我看來,我從來沒有看到錯誤信息。默認的驗證器(如檢查required
字段的驗證器)工作。
任何想法?
你已經張貼作爲回答不正確的原因,你的代碼無法正常工作。你能展示你在視圖中做了什麼嗎?以及您正在驗證/保存的控制器操作? – 2012-03-28 04:07:28