Друзья, никак не могу понять почему на странице вылазит "Error 500
Property "CEmailValidator.0" is not defined." Как мне кажется, дело не во вьюшке, потому что поробовал создать форму с помощью CHtml, всё равно выходит эта ошибка.
моделька:
class User extends CActiveRecord
{
const SCENARIO_REGISTER = 'register';
public $password_repeat;
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'user';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('username, password, cookie', 'required'),
array('username', 'unique'),
array('username', 'length', 'min'=>5, 'max'=>30),
array('username', 'match', 'pattern'=>'/^[A-z][\w]+$/'),
array('password', 'length', 'min'=>6, 'max'=>30),
array('password_repeat', 'email', 'required', 'on'=>self::SCENARIO_REGISTER),
array('password_repeat', 'length', 'min'=>6, 'max'=>30),
array('password', 'compare', 'compareAttribute'=>'password_repeat', 'on'=>self::SCENARIO_REGISTER),
array('email', 'email', 'on'=>self::SCENARIO_REGISTER),
array('email', 'length', 'min'=>6, 'max'=>30),
array('email', 'filter', 'filter'=>'mb_strtolower'),
array('id, username, password, email, dtime_register, cookie', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'username' => 'Username',
'password' => 'Password',
'password_repeat' => 'Repeat password',
'email' => 'Email',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
*
* Typical usecase:
* - Initialize the model fields with values from filter form.
* - Execute this method to get CActiveDataProvider instance which will filter
* models according to data in model fields.
* - Pass data provider to CGridView, CListView or any similar widget.
*
* @return CActiveDataProvider the data provider that can return the models
* based on the search/filter conditions.
*/
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('username',$this->username,true);
$criteria->compare('password',$this->password,true);
$criteria->compare('email',$this->email,true);
$criteria->compare('dtime_register',$this->dtime_register,true);
$criteria->compare('cookie',$this->cookie,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return User the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
protected function beforeSave() {
if(parent::beforeSave()) {
if($this->getIsNewRecord()) {
$this->dtime_register = time();
$this->password = $this->hashPassword($this->password);
}
return true;
}
return false;
}
public function hashPassword($password) {
return md5($password);
}
}
метод в контроллере:
public function actionRegister() {
$user = new User(User::SCENARIO_REGISTER);
if(isset($_POST['User'])) {
$user->attributes = $_POST['User'];
if($user->validate()) {
$user->save(false);
$this->redirect($this->createUrl('user/'));
}
}
$this->render('register', array('model'=>$user));
}
и вьюшка:
<div class="form">
<? $form = $this->beginWidget('CActiveForm', array(
'id'=>'register-form',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
)); ?>
<div class="row">
<? echo $form->labelEx($model, 'username'); ?>
<? echo $form->textField($model, 'username'); ?>
<? echo $form->error($model, 'username');?>
</div>
<div class="row">
<? echo $form->labelEx($model, 'email'); ?>
<? echo $form->textField($model, 'email'); ?>
<? echo $form->error($model, 'email');?>
</div>
<div class="row">
<? echo $form->labelEx($model, 'password'); ?>
<? echo $form->textField($model, 'password'); ?>
<? echo $form->error($model, 'password');?>
</div>
<div class="row">
<? echo $form->labelEx($model, 'password_repeat'); ?>
<? echo $form->textField($model, 'password_repeat'); ?>
<? echo $form->error($model, 'password_repeat');?>
</div>
<div class="row submit">
<? echo CHtml::submitButton("Зарегистрироваться");?>
</div>
<? $this->endWidget(); ?>
</div>