2012-07-18 23 views
1

我想在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')); 
?> 
+4

'我得到一個error' - 錯誤信息總是有益的。 「一個錯誤」不如此。 – DaveRandom 2012-07-18 14:08:26

+0

對不起,沒有視覺錯誤,沒有做用戶模型的保存,所以if/else去別的 – simone 2012-07-18 14:10:00

+1

你可以顯示'save()'方法的代碼,所以我們可以看到哪裏/爲什麼它會返回一些評估爲「FALSE」的東西?同時顯示'var_dump($ this-> User-> save($ this-> data))'可能會有所幫助。 – DaveRandom 2012-07-18 14:11:08

回答

1

我看你用Auth組件。如果您的Auth::authorize默認值被覆蓋,請確保您授予用戶執行數據寫入的適當權限(也許他只允許讀取)。

另一個問題可能是您的$validate聲明在模型中,您強制用戶輸入字段值(使用'required' = true),但實際上該字段甚至不顯示在視圖上。如果在裏面定義了'on' => 'create',則可以避免對數據編輯進行此驗證規則。

此外,我會建議使用CakePHP debug()代替的var_dump()用於調試的目的。

+0

謝謝...正是這個問題!謝謝 – simone 2012-07-31 10:16:58

相關問題