我想在CakePHP中登錄的用戶創建的「編輯」個人資料頁面的編輯功能錯誤。這將是添加/編輯用戶信息的功能。 在$ this-> User-> save($ this-> data)函數中出現錯誤,我不明白是什麼問題。
public function edit() {
$this->User->id = $this->Auth->User('id');
if ($this->request->is('post')) {
if ($this->User->save($this->data)) {
$this->Session->setFlash(__('The user has been saved'), 'flash_success');
// $this->redirect($this->Auth->redirect());
} else {
var_dump($this->invalidFields());
$this->Session->setFlash(__('The user could not be saved. Please, try again.'), 'flash_failure');
}
} else {
//autocompleto il form
$this->data = $this->User->read(null, $this->Auth->User('id'));
}
}
的觀點是:
<?php
echo $this->Form->create('User',array('action' => 'edit'));
echo $this->Form->input('name', array('label'=> 'Name'));
echo $this->Form->input('surname', array('label'=> 'Surname'));
echo $this->Form->input('id', array('type'=> 'hidden'));
echo $this->Form->end(__('Submit'));
?>
'我得到一個error' - 錯誤信息總是有益的。 「一個錯誤」不如此。 – DaveRandom 2012-07-18 14:08:26
對不起,沒有視覺錯誤,沒有做用戶模型的保存,所以if/else去別的 – simone 2012-07-18 14:10:00
你可以顯示'save()'方法的代碼,所以我們可以看到哪裏/爲什麼它會返回一些評估爲「FALSE」的東西?同時顯示'var_dump($ this-> User-> save($ this-> data))'可能會有所幫助。 – DaveRandom 2012-07-18 14:11:08