2010-03-19 49 views
0

也許我錯過了一些東西,但在symfony示例中,在表單提交操作中沒有任何內容表示表單數據已保存到數據庫。 (link)。我怎樣才能保存所有的數據庫?從鏈接symfony保存已提交表格到數據庫

例子:

public function executeSubmit($request) 
{ 
    $this->forward404Unless($request->isMethod('post')); 

    $params = array(
    'name' => $request->getParameter('name'), 
    'email' => $request->getParameter('email'), 
    'message' => $request->getParameter('message'), 
); 

    $this->redirect('contact/thankyou?'.http_build_query($params)); 
} 
+0

你說得對。這些代碼不會將表單數據保存到數據庫中。 – bobo 2010-03-19 07:43:37

回答

1

如果你有一個是基於一個模型(例如學說或推進對象)形式,你需要做這樣的事情在你的行動如下:

$this->form = new MyForm(); 

$this->form->bind($params); 

if ($this->form->isValid()) 
{ 
    $this->form->save(); 
} 

這些似乎成爲你失蹤的關鍵步驟。正如其他人所指出的,Symfony教程提供了很好的例子。