2013-04-30 97 views
4

我想在視圖中製作測試表單。到目前爲止,我只有很簡單的領域,以測試是否一切工作的權利(這不是)Cakephp表單不提交

$this->Form->create('user', array('url'=>array('controller'=>'users', 'type' => 'post', 'action'=>'add'))); 
echo $this->Form->input('username'); 
echo $this->Form->end(__('Submit', true)); 

現在這個打印提交按鈕,當點擊它,我認爲,它會調用「添加」功能我的UsersController.php文件。

不過,我有這樣的事情在控制器文件

class UsersController extends AppController { 
    ....... 

public function add() { 
if ($this->request->is('post')) { 
    debug(TEST); die; 
    $this->User->create(); 
    if ($this->User->save($this->request->data)) { 
    $this->Session->setFlash(__('The user has been saved')); 
    $this->redirect(array('action' => 'index')); 
    } else { 
    $this->Session->setFlash(__('The user could not be saved. Please, try again.')); 
}}} 

    ........ 

} 

注意調試那裏在那裏,當我提交調試不打印測試並沒有任何反應在頁面上使我假設我的表單沒有正確提交。老實說,我不知道爲什麼,我一直立足我在這裏找到的解決辦法 How to submit form for one model in another's controller?

回答

4

找到了解決辦法,被卡住了幾個小時,因爲回聲創建表單前失蹤,我以爲那些只應該打印東東。我感到非常可怕

+0

適合所有人:)。你能否將自己的答案標記爲可以接受,以便正確標記它? – Nunser 2013-05-02 13:09:47