0
更新您好我試圖更新其已經保存在數據庫表中,但一些如何I T正在創造新的記錄,而不是更新現有的用戶數據一個。這是我的代碼。問題CakePHP中
function admin()
{
$conditions = "id";
$recursive = 1;
$data = $this->User->find('all');
$counter = $this->User->find('count');
$this->set('counter', $counter);
$this->set('combo', $data);
$username = $this->Session->read('user');
if ($username)
{
$results = $this->User->findByUsername($username);
$this->set('User', $results['User']);
$this->set('last_login', $this->Session->read('last_login'));
if (!empty($this->data))
{
$this->data["User"]["access_right"] = implode(",",$this->data["User"]["access_right"]);
$this->User->set($this->data);
if ($this->User->validates())
{
$this->data['User']['password'] = md5($this->data['User']['password']);
if($this->User->saveAll($this->data, TRUE, array('username','password','first_name','last_name','notes','access_right')))
{
$this->redirect(array('action' => 'admin'));
$this->Session->setFlash('User Data Updated.');
}
else
{
$this->Session->setFlash('There was a problem while Updating User.');
}
}
}
}
else
{
$this->redirect(array('action' => 'login'));
exit();
}
}
,這是我的模型
<?php
class User extends AppModel
{
var $name = 'User';
var $validate = array(
'username'=>array(
/* 'alphaNumeric'=>array(
'rule'=>'alphaNumeric',
'required'=>true,
'message'=>'Alphabets and numbers only'
), */
'between'=>array(
'rule'=>array('between', 5, 15),
'message'=>'Between 5 and 15 characters'
)
),
'password'=>array(
'rule'=>array('minLength', 8),
'required'=>true,
'message'=>'Minimum 8 characters long'
),
'email'=>'email'
);
}
?>