问题防御
我有一个名为“user.php”的模型我有一些验证规则如下重置表格我想检查该用户是否已注册,如果已注册用户将发送密码重置链接
我不知道如何验证这个电子邮件字段,任何帮助都非常重要,因为我是 YII 的新手
用户.php
class Users extends CActiveRecord
{
public $cpassword;
public static function model($className=__CLASS__)
{
return parent::model($className);
}
public function tableName()
{
return 'users';
}
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('email, password, user_type , cpassword','required'),
array('email', 'length', 'max'=>200),
array('email', 'unique'),
array('email', 'email'),
array('password', 'length', 'max'=>300),
array('cpassword', 'length', 'max'=>300),
array('user_type', 'length', 'max'=>5),
array('cpassword', 'compare', 'compareAttribute' => 'password'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, email, password, user_type ', 'safe', 'on'=>'search'),
);
}
public function relations()
{
return array(
);
}
public function attributeLabels()
{
return array(
'id' => 'ID',
'email' => 'Email',
'password' => 'Password',
'user_type' => 'User Type',
'cpassword' => 'Confirm Password'
);
}
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('email',$this->email,true);
$criteria->compare('password',$this->password,true);
$criteria->compare('user_type',$this->user_type,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
public function beforesave()
{
$this->password=md5($this->password);
return true;
}
}