Answer the question
In order to leave comments, you need to log in
Yii Framework: Why does "Error 500 Property "CEmailValidator.0" is not defined" appear?
Friends, I just can't understand why the page shows "Error 500
Property "CEmailValidator.0" is not defined." It seems to me that it's not about the view, because I tried to create a form using CHtml, this error still comes out.
modelka:
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>
Answer the question
In order to leave comments, you need to log in
The thing is in this line:
A couple of extra quotes turns the field name into a validator :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question