Yii 'Unique' CFormModel 中的验证器



Yii Framework中有一小段代码:

array('username', 'unique', 'attributeName'=> 'username', 'caseSensitive' => 'false'),

这给了我一个错误:

RegisterForm and its behaviors do not have a method or closure named "tableName".

完整的RegisterForm.php模型:

<?php
class RegisterForm extends CFormModel
{
    public $username;
    public $password;
    public $password2;
    public $email;
    public $fullname;
    public $birth;
    public function rules()
    {
        return array(
            array('username, password, password2, email, fullname, birth', 'required'),
            array('username','length','min'=>3),
            array('username','length','max'=>16),
            array('username', 'filter', 'filter'=>'strtolower'),
            array('username', 'ext.alpha', 'allowSpaces'=>'flase', 'allAccentedLetters'=>'false'),
            array('username', 'unique', 'attributeName'=> 'username', 'caseSensitive' => 'false'),
            array('password', 'length', 'min' =>6),
            array('password', 'length', 'max' =>32),
            array('password', 'compare', 'allowEmpty' => 'false', 'compareAttribute' => 'password2', 'strict' => 'true'),
            array('email', 'length', 'min' =>8),
            array('email', 'length', 'max' =>128),
            array('email', 'email'),
            array('fullname','length','min'=>6),
            array('fullname','length','max'=>64),
            array('fullname', 'ext.alpha', 'allowNumbers'=>'false', 'allAccentedLetters'=>'false'),
            array('birth', 'date', 'allowEmpty'=>'false', 'format'=>'dd/MM/yyyy'),
        );
    }
}

您必须在该验证器中指定一个附加属性className。它应该包含活动记录类的名称,该类的表应该检查其唯一性。

http://www.yiiframework.com/doc/api/1.1/CUniqueValidator#className-详细

最新更新