[英]Yii 'Unique' Validator in CFormModel
I have this small line of code in Yii Framework: 我在Yii Framework中有一小段代码:
array('username', 'unique', 'attributeName'=> 'username', 'caseSensitive' => 'false'),
that gives me an error: 这给了我一个错误:
RegisterForm and its behaviors do not have a method or closure named "tableName".
The full RegisterForm.php model: 完整的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'),
);
}
}
You have to specify an additional property, className
, in that validator. 您必须在该验证器中指定一个附加属性
className
。 It should contain the name of the Active Record class whose table should be checked for uniqueness. 它应包含Active Record类的名称,应检查其表的唯一性。
http://www.yiiframework.com/doc/api/1.1/CUniqueValidator#className-detail http://www.yiiframework.com/doc/api/1.1/CUniqueValidator#className-detail
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.