我有更改密码的操作。 我不明白为什么$ error为null;
public function actionChangePassword() {
$error;
$player = $this->loadModel(Yii::app()->user->id);
$oldpassword = '';
$newpassword = '';
$newpasswordrepeat = '';
if (!isset($_REQUEST['oldpassword']) || !isset($_REQUEST['newpassword']) || !isset($_REQUEST['newpasswordrepeat'])) {
$error = 'Vui long dien day du';
}
if (isset($_REQUEST['newpassword']) && isset($_REQUEST['newpasswordrepeat']) && isset($_REQUEST['oldpassword'])) {
$oldpassword = $_REQUEST['newpassword'];
$newpassword = $_REQUEST['newpassword'];
$newpasswordrepeat = $_REQUEST['newpasswordrepeat'];
if ($player->password != EncryptManager::encryptPassword($_REQUEST['oldpassword'])) {
$error = 'Password cu khong dung';
if ($newpasswordrepeat != $newpassword) {
$error = 'Lap lai password khong dung';
}
if (count($newpassword))
$error = 'Nhap password phai tren 6 ky tu';
if (!isset($error)) {
$player->password = EncryptManager::encryptPassword($_REQUEST['newpassword']);
echo 'new password';
if ($player->save()) {
$this->redirect(Yii::app()->baseUrl);
}
}
}
}
$this->render('//site/changepassword'
, array('error' => $error)
);
}
和我的观点更改密码
<div class="change-password-layout">
<div class="change-password-content" >
<?php echo CHtml::beginForm(); ?>
<div class="change-password-detail-total">
<div class="change-password-title"><p>Đổi mật khẩu</p></div>
<div class="change-password-detail">
<p>Mật khẩu cũ </p>
<input type="password" name="oldpassword" value="">
</div>
<div class="change-password-detail">
<p>Mật khẩu mới </p>
<input type="password" name="newpassword" value="">
</div>
<div class="change-password-detail">
<p>Xác nhận lại mật khẩu mới </p>
<input type="password" name="newpasswordrepeat" value="">
</div>
<div class="submit-button">
<input type="submit" name="" value="Xác nhận">
<input type="button" name="" value="Hủy bỏ" />
<div class="clearboth"></div>
</div>
</div>
<?php echo $error; ?>
<?php echo CHtml::endForm(); ?>
</div>
<div class="change-password-bg-total">
<div class="change-password-bg"></div>
</div>
<?php if ($error != '') { ?>
<div class="msg-error">
<div class="signup-line"></div>
<div class="msg-item">
<div class="msg-warning-icon"></div>
<div class="msg-warning-label">
<?php echo $error; ?>
</div>
<div class="clearboth"></div>
</div>
<div style="height:5px"></div>
<div class="signup-line"></div>
</div>
<?php } ?>
</div>
<script>
$("#set-height").css('height',$(window).height());
</script>
当用户未填写完整字段时,如果成功重定向到主页,则会出现错误消息。 谢谢提前!
答案 0 :(得分:1)
它被初始化为null,并且根据您的代码,只会初始化为
因此,如果您的用户输入了错误的“oldpassword”,那么就没有错误。
你想要一个 else 这个陈述。
if ($player->password != EncryptManager::encryptPassword($_REQUEST['oldpassword']))