【发布时间】:2011-10-18 12:09:01
【问题描述】:
我有一个用户控制器和用户模型。这个模型和关联的数据库表是用来认证的,自然有密码字段。
在我调用$this->data 时的edit 操作中,将散列密码放在我的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');
?>
我怎样才能有一个表单让用户编辑他们的帐户(用户名等),如果留空则不会更新密码,但如果用户在密码字段中输入新密码会更新它?
【问题讨论】:
标签: cakephp cakephp-1.3 cakephp-model