herbary
(Herba Nv)
1
Need custom validate method to check is value not equal zero with this way:
public function rules()
{
return array(
array('username, password, myvalue', 'required'),
array('myvalue1, myvalue2', 'nozero'),
);
}
public function nozero($attribute,$params)
{
if(!$param==0)
$this->addError('password','something wrong.');
}
I have no idea of code of nozero method to get access to myvalue1, myvalue2.
andy_s
(Arekandrei)
2
public function nozero($attribute,$params)
{
if($this->$attribute==0)
$this->addError('password','something wrong.');
}
mdomba
(Maurizio Domba Cerin)
3
Note that the custom validator function gets the attribute being validated in the parameter $attribute
so for the addError instead of using ‘password’ you may use $attribute to set the error message for the attribute being validated…