symfony save submitted form to database
Maybe I am missing something, but in symfony examples, in form submission action there's nothing which indicates form data is saved to database. (link). How can I save everything to db?
Example from the link:
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($param开发者_运维百科s));
}
If you have a form that's based on a model (eg Doctrine or Propel object), you'll need to do something like the following in your action:
$this->form = new MyForm();
$this->form->bind($params);
if ($this->form->isValid())
{
$this->form->save();
}
These seem to be the crucial steps that you're missing. As others have pointed out, the Symfony tutorials provide good examples of this.
Take a look at http://www.symfony-project.org/forms/1_4/en/04-Propel-Integration:
In a Web project, most forms are used to create or modify model objects. These objects are usually serialized in a database thanks to an ORM. Symfony's form system offers an additional layer for interfacing with Propel, symfony's built-in ORM, making the implementation of forms based on these model objects easier.
As well as VolkerK's link, the jobeet tutorial covers doctrine (or propel if you prefer that as your ORM) forms.
http://www.symfony-project.org/jobeet/1_4/Doctrine/en/10
精彩评论