what is this code doing in creating model


I am new to yii and currently reading definitive guide to yii.

i came across following code on Creating Model

what is the purpose of line

 array('password', 'authenticate'),

? is it calling function authenticate?

if it is calling authenticate function, then what are the vaues for $attribute, $params?


class LoginForm extends CFormModel


    public $username;

    public $password;

    public $rememberMe=false;


    private $_identity;


    public function rules()


        return array(

            array('username, password', 'required'),

            array('rememberMe', 'boolean'),

            array('password', 'authenticate'),




    public function authenticate($attribute,$params)


        $this->_identity=new UserIdentity($this->username,$this->password);


            $this->addError('password','Incorrect username or password.');



Welcome to the forum.

Yes, you can define either a build-in validator (see this wiki), a validator class or a class method. The actual validation method must have a special signature, means the 2 parameters are required even if you don’t need them (like the authenticate method). See here for more details.


so in above example ‘password’ is attribute for validator ‘authenticate’

this means


$this->addError('password','Incorrect username or password.');

can also be written


$this->addError($attribute,'Incorrect username or password.');

and as there are no other options specified in rule

array('password', 'authenticate'),

so $param is null.

am I going in right direction?

Yes correct. Since the attribute is known already within authenticate method, ‘password’ is used instead of $attribute.