注册时,$model->save() 没好使,也不出错误信息 [ 新手入门 ]
这是 userController
public function actionRegister()
{
$model = new User('register');
if(isset($_POST['User'])) {
$model->attributes = $_POST['User'];
$model->validate();
$model->getErrors();
if($model->save()) {
$this->redirect(array('user/login'));
}
}
$this->render('register', array('model' => $model));
}
model中的
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('email, password, passwordConfirm, nick_name, verifyCode', 'required', 'on'=> 'register'),
array('email, nick_name', 'unique'),
array('passwordConfirm', 'compare', 'compareAttribute' => 'password'),
array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
array('email', 'length', 'min' => '5', 'max' => 255),
array('password', 'length', 'min' => '4', 'max' => 18),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
//array('user_id, email, password, nick_name, last_login, create', 'safe', 'on'=>'search'),
);
}
public function beforeSave() {
if($this->isNewRecord) {
$this->salt = $this->verifyCode;
$this->password = md5($this->salt . $this->password);
$this->create = time();
}
}
如果我写出来的不够明确,请提出来,我再补
共 6 条回复
-
这是视图
<div class="form"> <?php echo CHtml::beginForm(); ?> <div class="row"> <?php echo CHtml::activeLabelEx($model, 'email'); ?> <?php echo CHtml::activeTextField($model, 'email', array('size' => 30, 'maxlength' => 100)); ?> <?php echo CHtml::error($model, 'email'); ?> </div> <div class="row"> <?php echo CHtml::activeLabelEx($model, 'password'); ?> <?php echo CHtml::activePasswordField($model, 'password', array('size' => 30, 'maxlength' => 100))?> <?php echo CHtml::error($model, 'password'); ?> </div> <div class="row"> <?php echo CHtml::activeLabelEx($model, 'passwordConfirm'); ?> <?php echo CHtml::activePasswordField($model, 'passwordConfirm', array('size' => 30, 'maxlength' => 100))?> <?php echo CHtml::error($model, 'passwordConfirm'); ?> </div> <div class="row"> <?php echo CHtml::activeLabelEx($model, 'nick_name'); ?> <?php echo CHtml::activeTextField($model, 'nick_name', array('size' => 30, 'maxlength' => 100))?> <?php echo CHtml::error($model, 'nick_name'); ?> </div> <div class="row"> <?php $this->widget('CCaptcha'); ?> <?php echo CHtml::activeLabelEx($model, 'verifyCode'); ?> <?php echo CHtml::activeTextField($model, 'verifyCode', array('size' => 8, 'maxlength' => 10))?> </div> <div class="row"> <?php echo CHtml::submitButton('注册', array('name' => 'submit'))?> </div> <?php echo CHtml::endForm(); ?> </div>
警匪
注册时间:2011-09-28
最后登录:2013-05-22
在线时长:0小时0分
最后登录:2013-05-22
在线时长:0小时0分
- 粉丝1
- 金钱55
- 威望0
- 积分55