パスワードを変更するアクションがあります。$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>
ユーザーがフィールドを完全に入力しないと、ホームページへのリダイレクトが成功した場合にエラー メッセージが表示されます。よろしくお願いします!