简体   繁体   English

symfony将提交的表单保存到数据库

[英]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. 也许我缺少了一些东西,但是在symfony示例中,在表单提交操作中,没有任何内容指示表单数据已保存到数据库。 ( 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($params));
}

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: 如果您有基于模型的表单(例如,Doctrine或Propel对象),则需要在操作中执行以下操作:

$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. 正如其他人指出的那样,Symfony教程提供了很好的例子。

Take a look at http://www.symfony-project.org/forms/1_4/en/04-Propel-Integration : 看看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. 在Web项目中,大多数表单都用于创建或修改模型对象。 These objects are usually serialized in a database thanks to an ORM. 由于有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. Symfony的表单系统提供了一个额外的层,用于与Symfony的内置ORM Propel接口,从而使基于这些模型对象的表单的实现更加容易。

As well as VolkerK's link, the jobeet tutorial covers doctrine (or propel if you prefer that as your ORM) forms. 和VolkerK的链接一样,jobeet教程也涵盖了教义(或者如果愿意,可以将其作为ORM)。

http://www.symfony-project.org/jobeet/1_4/Doctrine/en/10 http://www.symfony-project.org/jobeet/1_4/Doctrine/zh/10

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM