需要帮助,因为我还是Yii2的新手.我想在将密码保存到数据库之前加密密码.所以我使用的是sha1,但问题是当我在下面显示的控制器中应用这行代码时,表单中的密码字段有内容.
$ model-> password = sha1($ model-> attributes ['password']);
这是Controller创建方法:
public function actionCreate()
{
$model = new Employeeinformation();
//$model->password = sha1($model->attributes['password']);
$model->created_date = date('Y-m-d H:i:s');
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->employee_id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
Run Code Online (Sandbox Code Playgroud)
这是形式:
<div class="employeeinformation-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'employee_id')->textInput(['minlength' => true, 'maxlength' => true]) ?>
<?= $form->field($model, 'password')->passwordInput(['maxlength' => true]) ?>
<?= $form->field($model, 'last_name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, …Run Code Online (Sandbox Code Playgroud)