我想在将密码插入数据库之前更改要加密的密码,但它不起作用。上面写着密码太长了。
public function actionCreate() {
$model = new Users;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Users'])) {
$model->attributes = $_POST['Users'];
$password = $_POST['Users']['password'];
$model->password = md5($password);
if ($model->save())
$this->redirect(array('view', 'id' => $model->id));
}
$this->render('create', array(
'model' => $model,
));
}
您为..使用的数据库和数据类型是什么。。?如果您使用mysql,您可以使用char(32)或varchar(32。
并注意你的模型规则
public function rules() {
return array (
array('password', 'length', 'max'=>20),
//length means your strings password that you entered can not more than 20 character
//but its not effect with password encrypted result
);
}
可能会出现消息"密码太长",因为您的规则()验证器。