我有一个用户控制器和用户模型。该模型和关联的数据库表用于身份验证,自然有一个密码字段。
在我edit
打电话时的操作中,我$this->data
将散列密码放在我的密码字段中edit
。自然,我不想要一个包含 40 个字符值的密码字段,然后在保存时重新散列。
我的动作是这样的:
function edit($id) {
$this->User->id = $id;
if (empty($this->data)) {
$this->data = $this->User->read();
}
else {
if ($this->User->save($this->data)) {
$this->Session->setFlash('User has been updated.');
$this->redirect(array('action' => 'view', $this->User->id));
}
}
}
我的观点是这样的:
<h2>Edit User</h2>
<?php
echo $this->Form->create('User', array('action' => 'edit'));
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->input('first_name');
echo $this->Form->input('last_name');
echo $this->Form->input('email');
echo $this->Form->end('Save User');
?>
如何让用户编辑其帐户(用户名等)的表单,如果留空,则不会更新密码,但如果用户在密码字段中输入新密码,则会更新密码?